Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).
Tabs vs. spaces for whitespace: which to use? Tabs are good for indentation because their width can be customized (tabstop). On the other hand, spaces must be used to ensure text stays lined up across lines. Could we have best of both worlds by using both?
--->int...foo; --->float.bar;
Here, tabs (--->) are used for indentation, while spaces (.) are used for alignment. Change the value of tabstop, and the alignment of foo and bar is not affected.
Smart Tabs
The Smart Tabs plugin accomplishes the above by ensuring that tabs are only used at the beginning of lines, while spaces are used everywhere else.
Continuation lines
When expressions span multiple lines, we may want to line up the beginning of those lines with the beginning of the expression in the first line.
int f(int x, int y) { return g(x, y); }
To make Vim format the code in this way, :set cindent and :set cinoptions=(0,u0,U0. Using the latest version of the Smart Tabs plugin, the whitespace will be encoded as such:
int f(int x, ......int y) { --->return g(x, --->.........y); }
That makes the alignment of x and y independent of tabstop.
See also
- EmacsWiki: Smart Tabs Editor-agnostic article about implementing smarter tabbing behavior.
- Tabs vs. Spaces: The end of the debate Vim/Emacs tips for tabbing.
- Use Tabs in Source Code Spaces for alignment, but tabs for indentation.