Search and replace in Vim is done using this command:
If you start using Vim a lot, you start seeing a problem with this: you have to type the
old string that you want to search and be replaced. If this string is long and complicated, then it is a pain. It would be wonderful if you could magically get the word currently under cursor into this search and replace command.
In Vim, you can do this! Here you go:
- Navigate cursor to any letter of the word.
*. This highlights the word and also selects it.
Now type the command
:%s//new/. Notice that you are not providing any search string. Vim automatically picks up the last searched word for that! 🙂
Tried with: Vim 7.4 and Ubuntu 14.04