Skip to content

Comment on Pasting in command line Vim doesn't have to suck

Comments

When the author says "command line Vim" he means "Vim running in a terminal emulator".

And pasting to terminal Vim doesn't suck if your Vim is configured to detect mouse clicks or interface with the system clipboard. Using the system paste shortcut (command- or ctrl-V) in insert mode is not the way to do it.

Unless, of course, the system clipboard is on a different machine than the running copy of Vim. This is useful advice, you really don't have to be so negative about it just because you aren't in a situation where it's applicable.

If your ssh session has X11 forwarding enabled, and the remote terminal Vim has +xclipboard support, then you can use the "+P keystroke to paste directly from the clipboard into Vim.

  :set pastetoggle=<F5>
Wack F5, middle-click paste away.

Sure, that works great if you want to reach for the mouse.

As mentioned elsewhere, if your vim is compiled with clipboard support(:version and look for +clipboard), you can copy/paste from the clipboard.

* is the Linux selection register.

+ is your clipboard.

So yanking is just set paste, "+y or " * y, set nopaste. Similarly you can do a "+d in vim and ctrl-v it in your browser or anywhere you can access the clipboard. You can " * d/" * y and paste it with your middle mouse button.

The mouse has nothing to do with it...

If you paste method doesn't let vim know what's going on, use pastetoggle, otherwise don't.

Pretty sure vi does not care about, or is even able to detect, the difference between a middle-mouse and a shift-insert paste.

Unless your terminal emulator has mouse support and you ':set mouse=a' in Vim.

Or you can use shift+insert.

Good point on my wording, thank you. I will change that to make it less confusing. As for middle-click, I really don't want to use the mouse. I don't use it for pasting anywhere else, so why would I change that for Vim?

Although if you're using Vim over SSH from a Windows box, the :set paste command is useful to know.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.