Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Use + as default register only for yank command

Tags:

vim

clipboard

I'd like to use + register (system clipboard) only for yank command (that is, don't overwrite this register on dd or other commands).

:set clipboard+=unnamed

won't work, because it introduces dd overwriting described above.

like image 911
sheerun Avatar asked Nov 14 '12 14:11

sheerun


2 Answers

d is more like "cut" than "delete". What you get is normal behavior.

You can use the "black hole register", though: "_d. I have mapped it to <leader>d.

like image 178
romainl Avatar answered Oct 22 '22 10:10

romainl


You can overwrite the default yank commands so that they default to the system clipboard, unless another register is explicitly given:

:nnoremap <expr> y (v:register ==# '"' ? '"+' : '') . 'y'
:nnoremap <expr> yy (v:register ==# '"' ? '"+' : '') . 'yy'
:nnoremap <expr> Y (v:register ==# '"' ? '"+' : '') . 'Y'
:xnoremap <expr> y (v:register ==# '"' ? '"+' : '') . 'y'
:xnoremap <expr> Y (v:register ==# '"' ? '"+' : '') . 'Y'
like image 8
Ingo Karkat Avatar answered Oct 22 '22 09:10

Ingo Karkat