How to replace a single word under cursor?

后端 未结 5 1559
广开言路
广开言路 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:25

    I often find myself wanting to replace one word with another that I have yanked from elsewhere. The problem with the other solutions is that if you attempt to change a word, then your next paste will be that word that you deleted with cw.

    Try the following:

    1 "This first word should overwrite the second"
    
    yiw     yank inner word (copy word under cursor, say "first").
    ...     Move the cursor to another word (say "second").
    viwp    select "second", then replace it with "first". 
    

    Hope that's what you were looking for.

提交回复
热议问题