Vim Tips Wiki
Advertisement

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created June 6, 2009 · complexity basic · version 7.0

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

Comments

Advertisement