Tuesday, August 6, 2019

Re: Persist Clipboard after Exiting Vim

Tony Mechelynck <antoine.mechelynck@gmail.com> wrote:
> Michael Partridge <mcp292@nau.edu> wrote:
>> Is there a way to prevent the clipboard buffer from being cleared upon
>> exit?

This shows a fundamental misunderstanding of the clipboard in X11. It is
not a place where stuff is stored, but a promise to supply content by a
running app. When the app has exited, it can no longer fullfil promises
and there is no clipboard to speak of.

The Apple Macintosh clipboard dates back to Macs being single process
systems and they worked around this problem by making the system itself
own the clipboard selection. It gave it persistence through application
launch and exits but also (particularly for large copies/cuts) imposed
a noticable resource drain on the system.

However that model of clipboard has become the one that most people use
when thinking about cut and paste, which makes the very different X11
one seem to behave weirdly.

>> The behavior I'm looking for is to use the system clipboard for yank,
>> etc. procedures. I have achieved this by putting 'set
>> clipboard=unnamedplus' in my config file. This puts yanked content into
>> my system clipboard where I can Ctrl (+ Shift) + V the content anywhere
>> else in my window-space, until I close Vim, at which point the buffer
>> gets cleared.

This is why there are tools like xclip that run background daemons to
hold on to a selection for fullfilling the content supply promise of
the clipboard.

>> I have noticed that paste 'p' still works between Vim files after
>> closing, which makes it seem like the content is still in the buffer,
>> but then why isn't it accessible via Ctrl (+ Shift) + V?

Vim, I expect, is storing it out of band, such as in ~/.viminfo .

> Using Ctrl+Shift+V in konsole uses konsole's pasting mechanism, a Vim
> running in konsole sees nothing; xterm is not even aware of the X11
> clipboard and uses only the <MiddleMouse> selection.

I don't know how st or konsole does it, but in xterm middle mouse and
shift-insert are fully configurable, as part of XTerm.vt100.translations.

Default translation for shift-insert:
Shift <KeyPress> Insert:insert-selection(SELECT, CUT_BUFFER0)

Deault translation for middle button paste:
~Ctrl ~Meta <Btn2Up>:insert-selection(SELECT, CUT_BUFFER0)

Where "~" means "without this modifier". In the xterm manpage, the
section on ACTIONS has documentation on the "functions" like
"insert-selection", but the documentation on the right hand side is
much harder to find. (And overall, XTerm.vt100.translations is a
cumbersome control method. It's a single unquoted string that needs
embeded newlines to be interpreted correctly, and can't support
inline comments.)

Elijah

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/46349k0tgwzfYL%40panix5.panix.com.

No comments:

Post a Comment