Some time back we wrote about a tip to fix vim indentation getting problematic when copy-pasting. That works great -- but only if the original code that you are copying is indented properly. It may be indented properly but with different indentation settings (tabs instead of spaces, indent of 2 or 8 spaces instead of your favourite of 4 spaces). When added to the your code, it stands out awkwardly from the rest of the code.
Here’s another use case -- as programmers, we often encounter badly indented code and if its a new piece of code that you are looking at trying to comprehend before you make changes, bad indenting is a big downer.
So what do you do? Indent the code to match the rest of the code? Manually?
Here’s a faster way -
1. Visually select the offending lines of code
2. Press = (equal)
Magic! All this is required to be done to align a piece of code copied with a different indentation to the current code’s indentation.
Following are the before and after snapshots that illustrate how it works.
Please try the above and let us know your feedback in the comments section. You can always submit useful tools web services and tips to us.