Cheat Logo

Cheat Sheet

Search and replace

Level: Intermediate
Programs:
  • vim

vim uses regular expressions for search and replace.

use /foo to find foo in the text.

s/foo/bar replaces all foo on a line with bar.

To replace all foo with bar in the whole file use g/foo/s//bar/g

When searching for text it can be helpful to highlight all occurrences. To enable this use the command :set hlsearch. To disable it use :set nohlsearch.

To search for foo and replace it with bar within a visual selection use :%s/\%Vfoo/bar/g.

©2015 Schutt Design (Luke & Noel Schutt).
Contact us using one of our first names at schuttdesign dot net.