vim toggling buffer overwrite behavior when deleting

前端 未结 2 1922
粉色の甜心
粉色の甜心 2020-12-11 08:38

Vim is great, but like many people I get really annoyed when I want to copy, delete, then paste -- the yank buffer gets overwritten by the delete action.

Now I know

2条回答
  •  忘掉有多难
    2020-12-11 09:11

    OK, I got it -- this script in .vimrc lets me effectively toggle a "no buffer side-effects" mode whereby the d and x keys no longer overwrite the buffer when "no buffer side-effects" mode is activated.

    Add this in .vimrc

    function! ToggleSideEffects()
        if mapcheck("dd", "n") == ""
            noremap dd "_dd
            noremap D "_D
            noremap d "_d
            noremap X "_X
            noremap x "_x
            echo 'side effects off'
        else
            unmap dd
            unmap D
            unmap d
            unmap X
            unmap x
            echo 'side effects on'
        endif
    endfunction
    nnoremap ,, :call ToggleSideEffects()
    

    Then to toggle in and out of this mode use the key combination ,, (two commas)

提交回复
热议问题