Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

Thanks!

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

2 Answers 2

For copying to the clipboard, I use

"*y

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
1  
Yup, * register is closer to question as xclip uses the PRIMARY selection by default, too. –  user112553 Jun 10 '11 at 12:33

Instead of %!xclip use

%w !xclip

Note the space between the w and the !. See

:help :w_c
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.