Copy, Paste and Visual Mode
The default behavior of vim doesn't copy to your OS clipboard, but instead copies to a register, which can also be the OS clipboard.
Copy and paste with specifying registers
To yank (copy) a text, you can copy the text from NORMAL mode with the y operator combined with a movement ,or you can enter visual mode with v and yank the text with y.
A text is copied to the registers when you change and delete text too.
To paste the yanked result you can use:
p- paste after the cursorP- paste before the cursor<M-p> (Alt+p)- paste in insert mode
Visual Modes
v- Normal Visual modeV- Visual Line mode, selects text by lines<C-v>- Visual Block mode, selects text by block
You can replace text by pasting new text after selecting the text to replace with visual, this action copies the replaced text to a register too.
Registers
To specify a destination for the copy use ".
For example to copy to register a I'll hit these keys: "ay<movement>".
Same for pasting: "ap.
Use _ - as the black hole register, when you want to delete a text without transferring it to a register.
There are many things you can do with registers, I suggest to briefly read :help registers.
Binds to delete/change/replace without yanking.
map('x', '<leader>p', '"_dP', 'Replace without yanking')
map('n', '<leader>d', '"_d', 'Delete without yanking') -- e.g <leader>dd deletes the current line without yanking it
map('n', '<leader>D', '"_D', 'Delete until EOL without yanking')
map('n', '<leader>c', '"_c', 'Change without yanking')
map('n', '<leader>C', '"_C', 'Change until EOL without yanking')
Using the OS clipboard
+ is the OS clipboard register, you can yank to it and you can paste from it.
I use these binds to use the OS clipboard without too many key presses:
map('', '<leader>y', '"+y', 'Yank to clipboard') -- E.g: <leader>yy will yank current line to os clipboard
map('', '<leader>Y', '"+y$', 'Yank until EOL to clipboard')
map('n', '<leader>p', '"+p', 'Paste after cursor from clipboard')
map('n', '<leader>P', '"+P', 'Paste before cursor from clipboard')
Plugins
Put/Yank Improvements
- yanky.nvim to cycle fast in my copy history after pasting instead of using the
registers. - peekup - dynamically interact with vim registers.
- registers.nvim to see the registers before yanking from/to them.