Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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 =.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top