[sf-lug] is there a way to open the clipboard in vi?

Akkana Peck akkana at shallowsky.com
Thu Jan 3 12:13:26 PST 2013

Michael Shiloh writes:
> select a portion of text in something (e.g. mail)
> edit to my hearts content
> close vi which writes the vi buffer back to the select buffer
> paste result in final destination

Install the xclip program, then do something like this:

xclip -out -selection primary >/tmp/clip; vi /tmp/clip; xclip -in -selection primary < /tmp/clip

Of course, you'd make that an alias if you wanted to do it very often.

My vim adds a newline to files that don't initially have one, so
if yours does too (I'm fairly sure that's a configuration option)
you'd probably want to change that or call vi with a special
config file.

I've had some problems with xclip on multi-line selections, and
I ended up writing a Python program to use instead.  My python
program eliminates newlines so you don't want to use it verbatim,
but if you have any problems with multi-line selections you might
want to consider an option like that -- and then you could call
vi from the same script.


More information about the sf-lug mailing list