Monday, August 6, 2018

Re: why is cut and paste broken on X11?

Well, I can't speak for you, but I've been using gvim (with GTK2 GUI)
for years on X11 and for me copy, cut and paste work with no problems.
The workings of the X11 clipboard may have to need some getting used
to for someone raised and bred on Windows, though, because it doesn't
work exactly the same way as the Windows clipboard.

- Of course, your Vim has to be compiled with +clipboard but if it's a
GUI it usually is.
- There are actually more than one separate "clipboards" on X11. One
of them is called "selection" in the X11 documentation: it is set by
most programs (but usually not Vim) as soon as you select something
visually and its contents can be pasted by a middle-click. To Vim,
this is the * (star) register, set by "*d "*y or :d* :y* and pasted by
"*p "*P or :put * This is usually not the one I use, except when I
need to paste into xterm, which doesn't know the other one.
- The other one is called "clipboard" in the X11 documentation and it
is used in all programs I know (including gvim) by Edit→Copy, Edit→Cut
and Edit→Paste. In addition, Vim knows it as the + register and uses
it with "+y "+d "+p "+P :y+ :d+ and :put +
- These two registers work best in gvim because when running Vim
(compiled, of course, with +x11 +clipboard) in an X11-aware terminal,
the terminal may (depending on which terminal application you are
using) steal selections and middle clicks and not let Vim see them. In
addition, usually neither of them works in tty1..tty6 (usually
accessed by Ctrl-Alt-F1..Ctrl-Alt-F6 and left by Ctrl-Alt-F7) because
these "Linux consoles" have no connection to the X11 server.
- When copying, cutting and pasting (sorry, in Vim language it is
yanking, deleting and putting, respectively) within a single instance
of Vim it is possible (and I recommend) to bypass the X11 selection &
clipboard completely, and use either the default register for
temporary use, or the 26 lettered registers "a to "z for stuff you may
want to remember, and put again and again at different places in
different edit files. I also find it handy to reserve register q for
macros, started (in that case) by qq then doing something in Normal
mode, and an additional q stops the registering.
- I usually set the 'clipboard' option to just "exclude:cons\|linux"
i.e. either :set cb-=autoselect or :set cb=exclude:cons\\\|linux (see
:h option-backslash about the backslash-escapes) so Vim will leave the
X11 selection well enough alone unless I explicitly say I want to use
it. For the same reason I keep the a and P flags out of 'guioptions'
(in my case I use :set go=!cgimrLtTp but YMMV).

Best regards,
Tony.

--
--
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.
For more options, visit https://groups.google.com/d/optout.

No comments: