Search code examples
vim

How to change a word in Vim (and all of its other occurrences)


I frequently use the combination c-a-w to change a word in Vim.

Are there any similar means by which one can quickly also change all other occurrences of said word in the specific file?


Solution

  • Use gn option for this purpose, in my case, I have a slightly different version of it

    " allows me to use a smarter cgn
    nnoremap c* *<c-o>cgn
    nnoremap c# #<C-o>cgn
    

    Now when you have to change a word many times, as long as you have not so many of it, because in this case, a classical substitution would be better, just press c* and then press "dot --> ." to change the next occurrencies of it.

    If you want to see how awesomeness gn can give us have a look at: Operating on search matches using gn (vimcasts)