Quickly indent multiple lines in vi/vim

Indenting lines of programming code is essential for readability. Indenting multiple lines at once is a feature that any useful code editing software should have.

As a programmer, I went far too long not knowing how to do this with vim (one of my favorite editors). It's so easy, even Mike Tyson could do it. And he never learned to read.

  1. Enter VISUAL LINE mode by holding [SHIFT] and hitting the "v" key.
  2. Use the arrow keys or "j" and "k" to select the lines you want to indent.
  3. Hit the ">" character (hold [SHIFT] and hit the "." key) to indent.

Then, you can repeat the indent using the "." key. Likewise, you can type the "<" character to outdent the selected lines.

Comments

  1. mohan

    This is extremely useful ..thanks for this

  2. Vdragon

    Thanks :)

Leave a Comment