Today I Learned

hashrocket A Hashrocket project

Re-indenting Your Code

If you have pasted some poorly formatted code or you've written a portion of code in a way that mangled the indentation, you can quickly re-indent that code for you. Or at least do its best to try and indent it correctly.

Make a visual selection of the code that you want to re-indent and then hit =.

For instance, this ruby code

if this_thing
p something
else
p nothing
end

will be indented by Vim as

if this_thing
  p something
else
  p nothing
end

See :h = for more details on how vim decides what formatting and indenting it will do.

h/t Chris Erin

See More #vim TILs
Every developer at Hashrocket is a Vim expert. Check out our development environment, Dotmatrix, and if you are in Chicago, come to the Vim Chicago Meetup hosted at our Chicago office.