Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to search and replace word under cursor in Vim

📅 2014-Oct-24 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

Search and replace in Vim is done using this command: :%s/old/new/.

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:

Tried with: Vim 7.4 and Ubuntu 14.04