Take the 2-minute tour ×

I'm just starting out in Vim. One feature I like is >> and << for indenting / unindenting a line without needing to place the cursor at the beginning of the line. I use a shiftwidth of 3, expanded to spaces.

My question is, when using >> or << is there a way to make that line "snap" to the nearest "perfect" indent? i.e. for me that would be the fourth column, seventh, tenth, and so on. This would be very handy to me at deeply nested indentation levels.

Alternatively (though slightly unsatisfying / less optimal): a way to remove all whitespace from the beginning of a line, then I could just use >> multiple times.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

The shiftround option will round to the nearest shiftwidth amount of space.

share|improve this answer
Perfect, that's exactly what I needed. Thanks. –  user2625911 Mar 4 at 3:26

Vim has automatic indentation modes. This is a somewhat big topic for one answer, but :help autoindent may be a good start.

Additionally, the == command will indent the current line according to the previous lines and the behavior of the current indent mode. (This applies the = filter to the current line.)

I usually apply == to a line first to "calibrate" it to the reference indentation, and from there fiddle with >> and <<.

Or, over multiple lines: visually select, then =.

share|improve this answer
Hi, this answer is also useful to me, thanks. I think by doing it all manually I am avoiding learning about Vim's autoindent features, and that may be the "real" problem. Cheers. –  user2625911 Mar 4 at 3:25
If you really want to go crazy with it, gg=G to just indent the whole file, or some subset of it as long as you can figure out the motion keystroke. –  QuestionC Mar 4 at 17:47

Your Answer


