VIM Replace word with contents of paste buffer?

后端 未结 9 1459
灰色年华
灰色年华 2020-12-22 15:41

I need to do a bunch of word replacements in a file and want to do it with a vi command, not an EX command such as :%s///g. I know that this is the typical way

9条回答
  •  一整个雨季
    2020-12-22 16:05

    Using the information in this post, I have formed this useful mapping. I chose 'cp' because it signifies "change paste"

    nmap cp "_cw"

    EDIT:

    Also I took this a step further and supported any motion.

    To get the equivalent of command above it would be cpw for "change paste word"

    "This allows for change paste motion cp{motion}
    nmap  cp :set opfunc=ChangePasteg@
    function! ChangePaste(type, ...)
        silent exe "normal! `[v`]\"_c"
        silent exe "normal! p"
    endfunction
    

提交回复
热议问题