diff --git a/README.md b/README.md index f4cda6f..8e62ec1 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Quick File Info](vim/quick-file-info.md) - [Quick Man Pages](vim/quick-man-pages.md) - [Quick Quickfix List Navigation](vim/quick-quickfix-list-navigation.md) +- [Re-indenting Your Code](vim/reindenting-your-code.md) - [Rename Current File](vim/rename-current-file.md) - [Repeat The Previous Change](vim/repeat-the-previous-change.md) - [Scrolling Relative to the Window](vim/scrolling-relative-to-the-window.md) diff --git a/vim/reindenting-your-code.md b/vim/reindenting-your-code.md new file mode 100644 index 0000000..55d08fe --- /dev/null +++ b/vim/reindenting-your-code.md @@ -0,0 +1,33 @@ +# 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 + +```ruby +if this_thing +p something +else +p nothing +end +``` + +will be indented by Vim as + +```ruby +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](https://twitter.com/MCNormalMode)