How to search and replace in current line only?

Viewed 34187
4 Answers

Confirm (c) and Replace :

:s/foo/bar/gc

Find the occurrence of 'foo', and before replacing it with 'bar' ask for confirmation.

Vim gives you these options :

replace with bar (y/n/a/q/l/^E/^Y)?
  • y - yes
  • n - no
  • a - replace all occurrences
  • q - quit
  • l - replace the current and stop (last)
  • ^E (CTRL + e) - scroll down
  • ^Y (CTRL + y) - scroll up

Now, in your case you can use the combination of y, n and l to achieve your purpose.

Related