Cheatsheet Pages / Vim Cheatsheet

How to find and replace on the current line in Vim — :s with g and c flags

One line needs a substitution — everywhere on that line (g), or with a confirmation prompt for each hit (c).

Almost every entry was run headless in Vim 9.1 and the resulting file checked; the few entries a tiny build cannot run (system clipboard, persistent undo, the sudo save) were verified against Vim's own documentation instead.

:s/foo/bar/     " replace the FIRST foo on this line
:s/foo/bar/g    " g = global: every foo on the line
:s/foo/bar/gc   " c = confirm: Vim asks y/n for each match before touching it
Vim Cheatsheet one-page card — commands that actually work
The full one-page card — Vim Cheatsheet. Get the complete cheatsheet on GitHub