💾 Archived View for thatit.be › 2023-09-24-11-51-55.gmi captured on 2023-12-28 at 15:22:22. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-11-14)

➡️ Next capture (2024-02-05)

-=-=-=-=-=-=-

how the mouse sucks in vim

With respect to copy paste

Copy & Paste is inconsistent in Vim when the mouse enters the picture. If you use the mouse for resizing panes, it works great, but not so much for copy and paste.

Some background

In the land of Linux and Xorg (it applies to some others, but this is where I live) there are three clipboards. Primary, Secondary, and Clipboard.

The primary is something I’ve always called the selection clipboard. Applications are asked what is selected in order to get the content of the selection clipboard.

The secondary is something I never interact with. Technically you can with xclip and others, but I never have.

The clipboard is less transitive than the primary and secondary and will hold contents shoved into it until new content is shoved into it. Sure, the primary arguably holds what it held until something new is put in, but the primary is more transient in that any selection typically replaces the selection content with the new selection. When the selection is cleared, the selection clipboard is also cleared. I tend to call the clipboard this the copy clipboard because it has its own copy of whatever is in it and persists beyond the death of the source program providing the selection cipboard.

I don’t know what other people call all these clipboards. I call the primary the selection clipboard and the clipboard the copy clipboard.

My expectations

I’m used to dealing with the primary/selection and the copy clipboard. I expect them to behave as they have. And I can only assume that this is not the same expectation that others have. And so it’s not the behavior I see in Vim or Neovim when the mouse is “enabled”.

What do I see

In both Vim and Neovim the mouse and clipboard support just seem to be broken. If I highlight a thing, it doesn’t go in the selection clipboard. If I cheat and hold a button specific to that terminal it will be in the selection, but then I can’t paste it into another window with the middle click if that other window is a Vim or Neovim window unless I unset the mouse. It seemingly gets random content pasted instead. Even the :registers command seemingly lie to my face and claim that "+ and "* contain the value it’s pasting instead of something I’ve selected or placed in the buffer.

For example, values explicitly inserted via xclip will usually be honored, so that tells me the terminal I’m using isn’t always putting things in the clipboards I expect to see.

Oh, and this is with the clipboard feature compiled into both Vim and Neovim. Pushing into the registers explicitly does put it in the copy clipboard for pasting outside of Vim/Neovim.

When does it behave “as expected”?

When the mouse is used in the same terminal to make a selection and then paste somewhere, it appears to do what would otherwise be expected. But the problem is that the content doesn’t go into the selection clipboard, it’s pushing/pulling from a register within vim instead of the Xorg/Wayland/Whatever clipboard. It also doesn’t go to the copy clipboard.

Other people

Other people expect a pasted whatever to be inserted where the mouse pointer is clicked. I expect it to paste wherever I have put the text cursor in the terminal, not where I have put the mouse cursor. Probably the result of using terminals in X before “clipboard support” started becoming available in terminal apps.

Annoyingly this means middle clicking on the terminal indiscriminately will cause the text cursor to relocate before pasting, so instead of being able to just middle click to insert content, I have to be extra cautious where the mouse is, which means slowing down, carefully positioning the mouse, and then middle clicking.

Workarounds

With mouse set to nvi or a you can enter command mode with a : and then make a selection without being interfered with. You can typically also use the shift key before making a terminal selection to get stuff into the selection clipboard.

The problem with pasting from the selection clipboard is that if mouse is set to a or nvi then content typically will not paste correctly, even with :set paste on. If the environment is right, a helper program like xclip or xsel can be :read !.... Or for some terminals, you can hold shift while middle clicking. On others you can use your input method editor to bring up a graphical clipboard and choose from the selection clipboard or the copy. And in some you can control+shift+v if it’s in the primary clipboard.

To fit more information in the clipboard, provided that the environment is right, you can shell out to xclip to read content into or out of whatever clipboard is desired. And typically using those helpers avoids issues with interpreting the format of input text.

Tags

#index

#vim

#cli

Navigation

index

tags

prev ⏰

⏰ next

updated: 2023-09-24 11:54:19

generated: 2023-11-11