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 > · par: 4 keystrokes (vimgolf rules — every keypress counts).

Why it works

> indents, < dedents; in visual mode they act on the selection and drop you back to normal mode. As an operator: >j indents this line and the next, >2j grabs three.

Variations

KeysWhat it does
Vjj >indent three lines
>2jindent three lines without visual mode
gvreselect to indent again
=auto-indent the selection

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.

Practice free — no signup →

Keep going