Indenting in Vi

Just a quick post here. Today I was writing a perl script and I had a 29 line block of code I wanted to indent. After a bit of research (thanks stackoverflow), I found what I was looking for.

If you want to indent a block surrounded by braces/brackets, select the top brace/bracket with the cursor…

Type <% to indent the entire block

Type <% to unindent the entire block

This is without going into insert mode (hint: if vi is actually typing your commands, hit escape).

To indent based on a number of lines, use the following

Type 5>> to indent five lines starting where your cursor is

Type 9>> to unindent nine lines starting where your cursor is

I hope that helps someone. It made my day a few notches better, that’s for sure.

That’s all for now. Signing out.

Category:Linux Category:Editors