How to paste over without overwriting register

后端 未结 10 2570
粉色の甜心
粉色の甜心 2020-11-28 02:41

Does anyone know of a way to paste over a visually selected area without having the selection placed in the default register?

I know I can solve the problem by alway

相关标签:
10条回答
  • 2020-11-28 03:33

    I don't like the default vim behavior of copying all text deleted with d, D, c, or C into the default register.

    I've gotten around it by mapping d to "_d, c to "_c, and so on.

    From my .vimrc:

    "These are to cancel the default behavior of d, D, c, C
    "  to put the text they delete in the default register.
    "  Note that this means e.g. "ad won't copy the text into
    "  register a anymore.  You have to explicitly yank it.
    nnoremap d "_d
    vnoremap d "_d
    nnoremap D "_D
    vnoremap D "_D
    nnoremap c "_c
    vnoremap c "_c
    nnoremap C "_C
    vnoremap C "_C
    
    0 讨论(0)
  • 2020-11-28 03:34

    Luc Hermitte's solution works like a charm. I was using it for about a week or so. Then I discovered a solution from Steve Losh's .vimrc that works nicely if YankRing is part of your plugin/bundle lineup:

    function! YRRunAfterMaps()                                                                                                      
        " From Steve Losh, Preserve the yank post selection/put.    
        vnoremap p :<c-u>YRPaste 'p', 'v'<cr>gv:YRYankRange 'v'<cr> 
    endfunction  
    
    0 讨论(0)
  • 2020-11-28 03:34

    try -

    :set guioptions-=a
    :set guioptions-=A
    
    0 讨论(0)
  • 2020-11-28 03:37

    In your .vimrc

    xnoremap p "_dP
    

    I found this from a response on a similar thread, but the original source was http://vim.wikia.com/wiki/Replace_a_word_with_yanked_text. It mentions some drawbacks, however it works fine for me.

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