If you press * in Vim, the editor will search for the next occurrence of the term in the same file. It saves you from having to type out the term.
Is there a quick way to replace the term currently under the cursor with a new one? One character to issue the command, typing in the new term, then Enter.
Press y to replace the match or l to replace the match and quit. Press n to skip the match and q or Esc to quit substitution. The a option substitutes the match and all remaining occurrences of the match. To scroll the screen down, use CTRL+Y , and to scroll up, use CTRL+E .
Open the file in Vim. Press slash (/) key along with the search term like “/ search_term” and press Enter. It will highlight the selected word. Then hit the keystroke cgn to replace the highlighted word and enter the replace_term.
Just use * and then:
:%s//new value/
If you don't specify a pattern, the substitute command uses the last searched one. Depending on the value of gdefault
in your configuration, you might need to add a /g
modifier to that command.
You can use:
:%s/<c-r><c-w>/new value/g
where <c-r><c-w>
means to literally type CTRL-rCTRL-w to insert the word under the cursor.
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