Vim Search and Replace More

You can search and replace in vim using the :s (substitute) command.

s will substitute on the current line. For example, the following will only replace the word potatoe on the current line:
%s will substitute on all lines in the file. For example, the following will replace the first occurrence of potatoe on every line:


  • g - Global (All occurrences)
  • c - Ask for confirmation
  • i - Case insensitive
  • I - Case sensitive



When using the substitute command you can use other delimiters other than \'/\'. This is useful if you\'re replace something like a URL with a lot of slashes in it. E.g: