I frequently have my cursor on a word where I would like to replace all occurrences of that word with another word. What is the easiest way to replace all occurrences of the word under the cursor with another word?
Use <C-r><C-w>
to insert the word under the cursor in the command line:
:%s/<C-r><C-w>/bar/g
If you need to do that a lot, you can easily create a mapping like this:
nnoremap <F6> :%s/<C-r><C-w>/
The mapping above inserts the first part of the command, ready for you to type the replacement, any flag and hit <CR>
:
:%s/foo/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With