Wikia

Vim Tips Wiki

GNU/Linux clipboard copy/paste with xclip

Talk0
1,610pages on
this wiki
Revision as of 10:56, August 11, 2011 by JohnBot (Talk | contribs)

Tip 964 Printable Monobook Previous Next

created 2005 · complexity basic · author Al Vega · version 6.0


From http://people.debian.org/~kims/xclip/

xclip is a command line utility that is designed to run on any system with an X11 implementation. It provides an interface to X selections ("the clipboard") from the command line. It can read data from standard in or a file and place it in an X selection for pasting into other X applications. xclip can also print an X selection to standard out, which can then be redirected to a file or another program.

I have had a lot of pain with the clipboard until xclip appeared in scene. I mix it with Vim in the following way:

:map <F7> :w !xclip<CR><CR>
:vmap <F7> "*y
:map <S-F7> :r!xclip -o<CR>

Press F7 to copy all current buffer to clipboard, or a selection, or press shift-F7 to paste all clipboard contents.

I prefer doing this way because "*p is slow with a lot of data.

Comments

I set the 'a' and 'A' options for guioptions, which copies gvim text to the clipboard. I'm using FC4/KDE.

The 'a' and 'A' options enables copying selected text to system clipboard

set guioptions=aAimrLT

Why use another utility when you can just have something like:

map <F7> gg"*yG<C-o><C-o>
map <S-F7> "*p

But it doesn't work with Vim 6.3.82.

"*y doesn't copy the selection into my XA_PRIMARY, XA_CLIPBOARD or secondary clipboard under RHEL4.0.2 with gnome.

The clipboard feature must be enabled at compile time. Check with vim --version | grep +clipboard. On Fedora the feature is enbaled only in vimx from the vim-X11 package.

This works for me - F6 to copy and F7 to paste:

vmap <F6> :!xclip -f -sel clip<CR>
map <F7> :-1r !xclip -o -sel clip<CR>

I like the above mapping for F6 and F7, but my position changes on the page when pasting with F7. Use this F7 map to preserve your location on the text file:

map <F7> mz:-1r !xclip -o -sel clip<CR>`z

The fakeclip plugin provides comprehensive keyboard shortcuts for +clipboard disabled Vim.


Around Wikia's network

Random Wiki