

Pasting Text Into Vim - whereiswaldo
http://stackoverflow.com/questions/3997078/how-to-paste-text-into-vim-command-line/3997110#3997110

======
antidoh
"I'd like to paste yanked text into Vim command line."

While the top voted answer is very complete, I prefer editing the command
history.

In normal mode, type:

    
    
      q:
    

This will give you a list of recent commands, editable and searchable with
normal vim commands. You'll start on a blank command line at the bottom.

For the exact thing that the article asks, pasting a yanked line (or yanked
anything) into a command line, yank your text and then:

    
    
      q:p
    

(get into command history edit mode, and then (p)ut your yanked text into a
new command line. Edit at will, enter to execute.

To get out of command history mode, it's the opposite. In normal mode in
command history, type:

    
    
      :q<enter>

~~~
india
Oh this is what that is! I accidentally reach this mode now and then and
wonder how I got there and what it does. I must be accidentally pressing q:
instead of :q ! This is great and useful. Thanks!

~~~
wmwong
Same here. You can also do q/ which gives you the history of your searches.

------
slurgfest
The title "pasting text into vim" is kind of wrong. This isn't really about
pasting text into vim, that is a very easy thing you learn in your first hour
of vim (press p or at worst "+p).

It is about the more meta activity of pasting text (e.g. representing a vim
command or an argument to a vim command) into the vim command line.

~~~
a3_nm
When I read "pasting text into vim", I thought of still another thing: ":set
paste".

~~~
nsheridan
My .vimrc contains: set pastetoggle=<F2>

Life is suddenly easier :)

~~~
tux1968
My .vimrc contains :

set pastetoggle=<Esc>[201~

noremap <Esc>[200~ :set paste<cr>0i

inoremap <Esc>[200~ <c-o>:set paste<cr>

cnoremap <special> <Esc>[200~ <nop>

cnoremap <special> <Esc>[201~ <nop>

let &t_ti="\<esc>[?2004h"

let &t_te="\<esc>[?2004l"

the ti/te sequences are passed from Vim to the client which tells Putty (and
others) to bracket all pasting with \e[200~ and \e[201~. The other commands
handle these sequences to make pasting happen transparently without having to
hit F2 ;o)

------
arocks
Not to start an editor war or anything. But a comparable feature set can be
found in Emacs[1].

[1]:
[http://www.gnu.org/software/emacs/manual/html_node/emacs/Reg...](http://www.gnu.org/software/emacs/manual/html_node/emacs/Registers.html)

~~~
tikhonj
You can also put window configurations into registers. C-x r w _r_ puts your
current window configuration (what windows you have open, their sizes and the
positions in their buffers) into register _r_ and C-x r j _r_ jumps to that
configuration.

I personally find this extremely useful--I use it far more than any other
register-based feature. Of course I effectively use Emacs as my window manager
for everything except web browsing, ergo I am certifiably insane.

And if ezbl or a similar project ever matures, I might start browsing from
Emacs too :P.

------
kevinburke
You can also yank from Vim to the system clipboard with

    
    
        "+y
    

Took me a year or so to learn that one

~~~
lloeki
Of course it only works for non-terminal vim. Someone may make it work on Mac
though by leveraging _pb{copy,paste}_ in some clever way (can't remember the
X11 equivalent ATM)

~~~
natedub
It can work in terminal vim, too.

I believe the special + register for the system clipboard is enabled by a
compile option, but that may not be entirely accurate. I have Vim 7.3
installed via Macports and it works for me.

~~~
mhd
Yes, it's the "+clipboard" option (as shown by :version). If you weren't doing
macports (or brew) already, the downloadable MacVIM version does include a
"Vim" binary that's usable on the commandline. Somewhere in
/Applications/MacVIM.app/... (can't check at work). Just symlinking or simply
setting `alias vim='<path_to_binary>` works perfectly.

[MacVim]: <http://code.google.com/p/macvim/>

------
LauriL
Here is how you can paste the word under cursor to the command line:

    
    
      C-r-w
    

Handy for renaming variables with _:%s/oldname/newname/g_ , for example.

------
s00pcan
Between the clipboard register ("+y "+p) and tmux's copy mode, I can move text
from pretty much anywhere to/from the command line.

------
bowyakka
Sorry I am a massive vim junkie, but why is this getting so much love ?

~~~
yitchelle
Maybe many HN readers are also VIMphiles.

~~~
itmag
That's correct, and there doesn't seem to be that many emacs people here. What
gives?

------
herouic
tmux buffers

Will solve your copy and paste problems across all UNIX applications.

Thank you Mr. Marriott. Great software.

~~~
ibotty
doesn't really help with content in vim's registers...

(but you are right, tmux is great)

