Vim: Use + as default register only for yank command

前端 未结 2 864
难免孤独
难免孤独 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 <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'
    
    0 讨论(0)
  • 2021-02-08 20:21

    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.

    0 讨论(0)
提交回复
热议问题