Indenting in Vim

May
27
2009
Tagged in , &

Ever had that situation where you've enabled :set paste and pasted in hundred of lines of code into vim only to see it all fully left aligned? I just did… And bugger going over each line and manually indenting it! Want know how to indent a visual block of text?

So, make a visual selection of what you'd like indented (by pressing v and moving the cursor to mark the selection). Press colon to enter command mode and type "le2". The le command is shorthand for left align. The 2 value is an optional indent setting.

This is what I love about vim; there is always a new trick to make your life easier!

Comment Icon

1 Comments

The most recent comment was on Thu, 1st Jul 2010, 18:59

Another solution

What about selecting lines instead of chars by pressing V (Shift+V), then having the selection automatically indented by pressing =?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <img> <p>
  • You can use BBCode tags in the text. URLs will automatically be converted to links.
  • You can enable syntax highlighting of source code with the following tags: <pre>, <code>.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.

Follow Me