Over time, unfortunately, some files start to contain a significant amount of mixed-up indentation (both from badly set-up IDEs and third-party contributions that came with tab indentation but went un-noticed). That's both tedious and error-prone to fix by hand.
A similar problem poses trailing whitespace. While it's just annoying in general, especially in HTML template files, it also increases page size unnecessarily by leading to more bytes transmitted on the wire, with no benefit to neither the users nor the developers.
Luckily, there are two quick fixes for these problems in both the editor vim and my IDE of choice, Komodo:
To remove tabs and replace them with spaces...
- in Komodo, select a code block, then click Code -> Untabify Region.
- in vim, type
:%s/\t/ /g(those are four spaces) -- or, as oremj points out in the comments, you could just to
And to wipe out trailing whitespace...
- in Komodo, in Preferences -> Editor / Save Options, activate the option "Clean trailing whitespace and EOL markers". Then open your document of choice and just save it again. However, when writing patches, you might want to refrain from keeping this option on at all times: It might result in confusion if a lot of lines are touched that do not have anything to do with the current patch. I wish there was a one-time way to run this, instead of a config option.
- in vim, type
:%s/\s+$//gwhich the regex-savvy among you have quickly decyphered as: "in the entire document, replace all one or more whitespace characters that are followed by a line ending with the empty string".