Learn Vim / How to Indent Multiple Lines in Vim

How to Indent Multiple Lines in Vim

The answerSelect the lines with V + j, then press > to indent (or < to dedent).

Try it on a real buffer

The function body forgot its indentation. Select lines 2–4 with j V jj, then press > to indent the whole selection one level.

def greet():
print("hello")
print("world")
return True

Canonical solution: j V jj > · target: 4 keystrokes — the fewest that solve it (every keypress counts).

Why it works

> indents, < dedents; in visual mode they act on the selection and drop you back to normal mode. Target counts j >2j (4 keys); selecting with V jj first is fine pedagogy.

Variations

KeysWhat it does
Vjj >indent three lines
>2jindent three lines without visual mode
gvreselect to indent again
=auto-indent the selection
▶ live vim buffertarget 4 keystrokes
The function body forgot its indentation. Select lines 2–4 with j V jj, then press > to indent the whole selection one level.

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

Sign in free to practice →

Keep going