Task-first Vim editing and navigation reference.

Editors

This page is for the Vim moves people search for most often: save and quit, replace text, copy lines, and navigate quickly.

Save & Quit
:wq

Example: Use this when you have finished editing and want to write changes before closing.

Gotcha: Command mode is required. Press `Esc` first if Vim is still in insert mode.

:q!

Example: Use this when you opened the wrong file or want to discard the current edit session.

Gotcha: This throws away unsaved edits in the current buffer.

Editing
:%s/old/new/g

Example: Use this for a whole-file replacement when the pattern is straightforward and you want a fast edit.

Gotcha: Add the `c` flag if you want confirmation for each replacement: `:%s/old/new/gc`.

Copy the current line

yy

Example: Use this in normal mode to yank the current line into Vim's unnamed register.

Gotcha: If you are in insert mode, press `Esc` first. `2yy` copies two lines.

Search
/pattern

Example: Type the pattern after `/`, press Enter, then use `n` and `N` to move through matches.

Gotcha: Search highlights can remain after the task. Use `:nohlsearch` to clear the visual highlight.



Vim Tutorial for Beginners

We need above all to know about changes; no one wants or needs to be reminded 16 hours a day that his shoes are on.

David Hubel

CodersTool Categories