Vim: use + as default case only for yank command

I would like to use + register (system clipboard) only for the yank command (that is, do not overwrite this register on dd or other commands).

 :set clipboard+=unnamed 

will not work because it enters the dd rewrite described above.

+6
source share
2 answers

You can overwrite the default yank commands so that they are by default in the system clipboard unless another register is explicitly specified:

 :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' 
+6
source

d more like "cut" than "delete". You get normal behavior.

You can use the "black hole register" though: "_d . I matched it with <leader>d .

+4
source

All Articles