How to replace a single word under cursor?

后端 未结 5 1561
广开言路
广开言路 2021-01-29 18:38

How do I replace a word under the cursor in Vim.

So instead of using dw then i then the word and then Esc, is there a simpler com

5条回答
  •  我在风中等你
    2021-01-29 19:21

    If you want to change a word with a previously yanked word, there's another solution to viwp (once you have yanked the first word).

    ciw removes the previous word and puts you in insert mode where it was. But then you can use ctrl+r, 0 to insert the contents of register 0 (which contain the previously yanked word).

    So:

    yiw
    [move to next word]
    ciw
    ctrl+r
    0
    

    This works better than viwp because after the first usage you can then repeatedly perform the replacement with .. It also doesn't switch into visual mode and highlight briefly.

提交回复
热议问题