Vim: Use + as default register only for yank command

前端 未结 2 863
难免孤独
难免孤独 2021-02-08 19:46

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

<         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-08 20:11

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

    :nnoremap  y (v:register ==# '"' ? '"+' : '') . 'y'
    :nnoremap  yy (v:register ==# '"' ? '"+' : '') . 'yy'
    :nnoremap  Y (v:register ==# '"' ? '"+' : '') . 'Y'
    :xnoremap  y (v:register ==# '"' ? '"+' : '') . 'y'
    :xnoremap  Y (v:register ==# '"' ? '"+' : '') . 'Y'
    

提交回复
热议问题