LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

How do you search in VIM?

/pattern searches forward (? backward), n/N jump to next/previous match, and :%s/old/new/g replaces throughout the file.

Search and replace is where vim gets genuinely fast. / finds; the substitute command :s replaces. The leading range decides scope: nothing = current line, % = whole file. The trailing flags decide behaviour: g=all matches on a line, c=confirm each, i=ignore case.

Search commands:

Command Action
/pattern Search forward
?pattern Search backward
n Next match
N Previous match

Example:

/error      " Find "error" forward
n           " Go to next "error"
N           " Go to previous "error"

Search and replace:

:s/old/new/         " Replace first on current line
:s/old/new/g        " Replace all on current line
:%s/old/new/g       " Replace all in file
:%s/old/new/gc      " Replace all with confirmation

Useful flags:

  • g = global (all occurrences)
  • c = confirm each replacement
  • i = case insensitive

Tip: Press * on a word to search for it instantly!

From Quiz: LIOS / Reading and Editing Files from the Command Line | Updated: Jul 14, 2026