Vim. Copying and pasting
Buffers, registers
Pasting
- Insertion mode
crtl+r ": from normal register
- Normal mode
p: from normal register
Pasting from a register.
- Insertion mode
ctrl+r letter_of_your_register
- Normal mode
" letter_of_your_register p
Copying
In normal mode:
- using mouse
- select with
vtheny - copy word
yw,y2w
Copying to a register: select your text with
v and then "qy with q
being an example of a register letter
Pasting
Start thinking in registers. Copying in pasting in vim is
more complex than ctrl-c ctrl-v,
be it for better or worse.
The most important things to keep in mind:
y: yank (yw - yank word)p: pastectrl+"*register: all vim deletes, cuts and yanks go into this register+register: all OS copies go into this register0register: only yanks will go into this register. Have you ever been frustrated with yanking something, then going to another line, deleting the unwanted word and then pasting with p the deleted word instead of the yanked? so next time you delete something withdw, usectrl+" 0to paste what you yanked and not what you deleted
https://stackoverflow.com/questions/2514445/turning-off-auto-indent-when-pasting-text-into-vim
To avoid messed up indentation after pasting use:
:set pasteThen paste your code. Note that the text in the tooltip now says -- INSERT (paste) --.
And turn it off after:
:set nopasteHowever, I always found that cumbersome. That's why I map
< F3 > such that it can switch between paste and
nopaste modes while editing the text! I add this to
.vimrc
set pastetoggle=<F3>