Learn Vim / How to Select Text in Vim

How to Select Text in Vim

The answerPress v to start a character-wise selection, stretch it with any motion (w, e, /pattern…), then operate on it (d, y, c).

Try it on a real buffer

Delete “absolutely completely utterly ” — but see it first: move onto “absolutely” (3w), press v to start a selection, stretch it with 3w, pull back one with h, then d.

This plan is absolutely completely utterly doomed.
Visual mode shows you the blast radius first.

Canonical solution: 3w v 3w h d · target: 5 keystrokes — the fewest that solve it (every keypress counts).

Why it works

In visual mode every motion stretches the selection, and operators act on what you can see. o swaps which end of the selection you're moving. Target counts the golf path (3w d3w = 5); your visual route is great practice even if it's a few keys longer.

Variations

KeysWhat it does
vcharacter-wise visual mode
Vline-wise visual mode
Ctrl-vblock (column) visual mode
oswap which end of the selection you're moving
gvreselect the last selection
▶ live vim buffertarget 5 keystrokes
Delete “absolutely completely utterly ” — but see it first: move onto “absolutely” (3w), press v to start a selection, stretch it with 3w, pull back one with h, then d.

Reading about keystrokes doesn't build keystrokes. Try this in a real vim buffer right now — the “See it, then cut it” mission takes about a minute.

Sign in free to practice →

Keep going