The following is a segment I added to my .vimrc
to allow for easy copy paste to the multiple clipboards in Linux/X11/freedesktop systems.
In essence, these systems usually have two clipboards, PRIMARY
and CLIPBOARD
.
CLIPBOARD
works as you expect from Windows; you highlight some text and CTRL+C
copies and CTRL+V
pastes.
PRIMARY
works a bit differently, any time you select text with the mouse, it is added to the PRIMARY
buffer; to paste it you use SHIFT+Insert
or the middle mouse button.
I suggest consulting the wikipedia article on clipboards in the X Window System.
"LEADERS AND TAG SHORTUCTS
"I have set a leader key to be used to let vim know that I want
"to do some sort of custom remapped command, i.e. those just below this
let mapleader =","
"in visual mode copy/cut/paste to CLIPBOARD (freedesktop.org specification, CTRL+C/CTRL+V)
vnoremap y "+y
vnoremap x "+x
vnoremap p "+p
"in visual mode copy/cut/paste to PRIMARY (freedesktop.org specification, Highlight/Shift+Insert)
vnoremap Y "*y
vnoremap X "*x
vnoremap P "*p
"in normal mode copy/cut/paste to CLIPBOARD (freedesktop.org specification, CTRL+C/CTRL+V)
nnoremap y "+y
nnoremap x "+x
nnoremap p "+p
"in normal mode copy/cut/paste to PRIMARY (freedesktop.org specification, Highlight/Shift+Insert)
nnoremap Y "*y
nnoremap X "*x
nnoremap P "*p
In short, how this works is that you select text in visual mode and type ,
followed by y
to copy the selection to CLIPBOARD
.
Likewise ,
followed by Y
to copy the selection to PRIMARY
.
And likewise x
or X
to cut and p
or P
to paste.
Pretty convenient.
PS:
Note that your version of vim must be built with +clipboard
and I think +xterm_clipboard
.
You can see whether this is the case with vim --version | grep clipboard
.
I note that Arch Linux is currently building without this feature.
You might consider installing gvim or something like that instead.