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.
Before
After
This is a guest post by one of the regular readers of Inficone – Srivats P . He is also the developer of the open source network traffic generator tool called Ostinato.
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.
Related posts:


I have not tried ‘VIM”. I found your article interesting, so I thought may I would give VIM a try. I am a PC use so I was happy to see there was a version available for Windows. I downloaded it and will give it. I am not much of a coder, but I do have to edit code quite often. Thanks for the tip!
Larry – Trust me – when you will start using vim, you will not go back to any other editor. Note that you need to give yourself a bit of time to use it properly. But once you get comfortable with it, there will be no looking back. You can download it from vim.org