Live data from Hacker News

Pasting in command line Vim doesn't have to suck

userobsessed.net

11–20 of 34 posts

Re: Pasting in command line Vim doesn't have to suck

#11

On a mac, you can use :r !pbpaste If you're ssh'd somewhere it's a different story. I've seen some things about sharing clipboards across shells, but I've never bothered to set it up. Also, copy-pasta makes for bad code.

Thanks for the tip! I also learned you can do:

:a!

and that will paste with properly formatted text.

Re: Pasting in command line Vim doesn't have to suck

#12
Vim can actually access the system clipboard (and, on Linux, the X clipboard). It's accessed as the * register (or + for the X clipboard). So, for instance:

    "*dd
    "*p
or

    "+yy
    "+P
And so on. Very convenient (and also much faster than Ctrl+V). On Ubuntu, this is only available in the Vim provided by vim-gnome or vim-gtk (even when running in a terminal).

Re: Pasting in command line Vim doesn't have to suck

#14

Vim can actually access the system clipboard (and, on Linux, the X clipboard). It's accessed as the * register (or + for the X clipboard). So, for instance: "*dd "*p or "+yy "+P And so on. Very convenient (and also much faster than Ctrl+V). On Ubuntu, this is only available in the Vim provided by vim-gnome or vim-gtk (even when running in a terminal).

It's only available when Vim is compiled with +xclipboard support. I actually found that on an older version of CentOS (v4, I don't know if it's different in newer versions), the 'vim' command and the 'gvim' command were separately compiled binaries so that 'vim' command didn't share the +xclipboard support. On Debian/Ubuntu, I believe they are the same binary.

Re: Pasting in command line Vim doesn't have to suck

#15

Earlier quoted context omitted.

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

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

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

Re: Pasting in command line Vim doesn't have to suck

#16
post #6
post #3

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.

Re: Pasting in command line Vim doesn't have to suck

#17
post #6
post #3

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.

[deleted]

Re: Pasting in command line Vim doesn't have to suck

#18

Earlier quoted context omitted.

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

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.

Re: Pasting in command line Vim doesn't have to suck

#19
post #2

... and I thought it was how to paste in vim commandline after :

ctrl-r pastes that register into your command.

So I often need to find "where is this method defined" across a large project.

    yw (yank word to get method into the " register)
    :Ack "  (ack plugin, paste that default " register)
     yay! I found it.
Alternately:

    /foo  (attempt to find foo in this file. Whoops, not there, where is it!).
    :Ack /  (last search is in the / register).
    There it is!

Re: Pasting in command line Vim doesn't have to suck

#20
post #14

Vim can actually access the system clipboard (and, on Linux, the X clipboard). It's accessed as the * register (or + for the X clipboard). So, for instance: "*dd "*p or "+yy "+P And so on. Very convenient (and also much faster than Ctrl+V). On Ubuntu, this is only available in the Vim provided by vim-gnome or vim-gtk (even when running in a terminal).

It's only available when Vim is compiled with +xclipboard support. I actually found that on an older version of CentOS (v4, I don't know if it's different in newer versions), the 'vim' command and the 'gvim' command were separately compiled binaries so that 'vim' command didn't share the +xclipboard support. On Debian/Ubuntu, I believe they are the same binary.

Exactly. On my machine (Ubuntu 11.04) the binary (/usr/bin/vim.basic) provided by the vim package is compiled with -clipboard -xterm_clipboard, and the binary (/usr/bin/vim.gnome) provided by vim-gnome is compiled with +clipboard +xterm_clipboard.
Post reply on HN