3

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!

1
  • 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
    Commented Jun 10, 2011 at 12:07

2 Answers 2

4

Instead of %!xclip use

%w !xclip

Note the space between the w and the !. See

:help :w_c
1

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.

1
  • 1
    Yup, * register is closer to question as xclip uses the PRIMARY selection by default, too.
    – peth
    Commented Jun 10, 2011 at 12:33

You must log in to answer this question.

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