Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to pipe selected text through an external command in vim, but not to replace the selected text with the output? Occasionally I want to copy something in a vim buffer to the X clipboard, so I use something like %!xclip -- but then I have to "undo" that command to get the text back since xclip doesn't return anything. Short of writing a wrapper script around xclip that also echoes the text back, is there a better way to do this?


share|improve this question
If you use gvim you can copy directly to the X clipboard with the special register +. "+yy copies current line to clipboard. You can also use visual selections. – Keith Jun 10 '11 at 12:07

Instead of %!xclip use

%w !xclip

Note the space between the w and the !. See

:help :w_c
share|improve this answer

For copying to the clipboard, I use


For more on the difference between between "* and "+, you'll want to check out :h x11-selection. For me, the following seems to be relevant:

Xterm, by default, always writes visible selections to both PRIMARY and CUT_BUFFER0. When it pastes, it uses PRIMARY if this is available, or else falls back upon CUT_BUFFER0. For this reason, when cutting and pasting between Vim and an xterm, you should use the "* register. Xterm doesn't use CLIPBOARD, thus the "+ doesn't work with xterm.

So I'll be sticking with "* instead of "+ that peth mentioned, but you might do well to test which ones works best for your usage pattern.

share|improve this answer
Yup, * register is closer to question as xclip uses the PRIMARY selection by default, too. – peth Jun 10 '11 at 12:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .