
Pasting in command line Vim doesn't have to suck - joefiorini
http://userobsessed.net/tips-and-tricks/2011/05/10/copy-and-paste-in-vim/
======
yesbabyyes
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).

~~~
sofal
Honest question: how is that faster than Ctrl+V? Is it because you don't need
the mouse?

~~~
yesbabyyes
I'm sorry for the confusion. There are two ways it can be faster. The way you
understood it, I guess, is in typing. The difference here is:

    
    
      i Ctrl v Esc
    

vs

    
    
      (Shift) " * p
    

Where, on my keyboard, both " and * requires the shift key, but YMMV.

What I meant, though, is the actual input of text. When pasting with Ctrl+V,
that's like one character at a time for Vim, and that's visible, so if you
paste a large body of text you can actually see it scrolling past. When
working with buffer commands, it works just any other internal Vim buffer
operation, which is instantaneous.

------
anurag
Vim has a built-in directive to toggle paste mode:

set pastetoggle=<F3>

[http://vim.wikia.com/wiki/Toggle_auto-
indenting_for_code_pas...](http://vim.wikia.com/wiki/Toggle_auto-
indenting_for_code_paste#Paste_toggle)

------
mpobrien
Another method I sometimes use for pasting large blocks of code:

    
    
        :r !cat
        (paste your stuff)
        ctrl - D
    

Doesn't require any switching between paste modes.

~~~
tzs
Nice idea, and you can replace cat if you need to clean up the paste:

    
    
        :r!perltidy
        (paste coworker's ugly perl code)
        ctrl-D
    

and you have nice looking code pasted.

------
graywh
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.

~~~
zosi
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.

~~~
pyre
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.

------
phaedrix
perhaps, I'm forgetting something, but these solutions seem overly
complicated.

I just have this in my .vimrc, and pasting (with formatting), is as simple as
copying text, going to vim and hitting 'p' in command mode.

    
    
      for middle-click (system) clipboard:
        :set clipboard=unnamed
      for ctrl-c (X11) clipboard:
        :set clipboard=unnamedplus
    
      couple caveats:
      * +xterm_clipboard
      * 'unnamedplus' is only for >= 7.3.74 
    

see here for more info
<http://vim.wikia.com/wiki/Accessing_the_system_clipboard>

note: I used unnamedplus for a bit, but found it to be much less desirable
than using the unnamed middle-click buffer...YMMV

------
hernan7
You can also paste in "ex" mode.

ESC

Q --> to go to "ex" mode

i --> to start inserting

paste text here

. --> line containing a single period to exit "ex" insert mode

:vi --> to return to "vi" mode

...golfer, moi?

------
bingaman
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.

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

:a! <paste like normal> <C-c>

and that will paste with properly formatted text.

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

~~~
cschneid
ctrl-r <register> 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 <ctrl-r>"  (ack plugin, paste that default " register)
        <enter> yay! I found it.
    

Alternately:

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

~~~
bawatski
wow! this is exactly what i was looking for. thank you.

------
oinksoft
"Argh, how do I paste?!"

    
    
      :h paste

