Vim Search and Replace

Vim separates searching (/) from substitution (:s). Together they let you find any text and rewrite it across the file without leaving the keyboard.

Steps

  1. Search forward. Press /, type your pattern, and press Enter to jump to the next match.
  2. Jump between matches. Press n to go to the next match and N to go to the previous one.
  3. Replace on the current line. Type :s/old/new/ and press Enter to replace the first match on the line; add g (:s/old/new/g) for every match on the line.
  4. Replace in the whole file. Type :%s/old/new/g and press Enter to replace every match in the file. Add i for a case-insensitive search.

In the Vim Browser Editor

Search and substitution both work in the Vim Browser Editor, including the g (global) and i (case-insensitive) flags.

Try it in the editor

Related how-tos

Advertisement