I already read a few questions and answers:
- Vim: use tabs for indentation, spaces to align with C source files
- Vim: aligning continuous lines with spaces
But not one of them offers a solution for me.
I really want to apply the Tabbed Indentation, Space Alignment principle, but when it comes to auto reporting, I couldn't teach Vim how to do this.
Consider the code assuming tabstops == 3 , shiftwidth == 3
( >-- means a tab, and . (dot) means a space):
{ >--long a = 1, >-->--..b = 2, >-->--..c = 3; }
Thus, it indents with tabs as much as possible, and then fills the rest with spaces. But actually this is a very bad approach: when someone reads this code with a different contribution size, the code will be corrupted. Here's how it would look with a contribution size of 8 characters:
{ >-------long a = 1, >------->-------..b = 2, >------->-------..c = 3; }
This is terrible. The problem is that Vim does not distinguish between indentation and alignment.
To make it look correct with any tab size, the code must be indented as follows:
{ >--long a = 1, >--.....b = 2, >--.....c = 3; }
Then this code will look beautiful no matter what tab size. For example, 8 characters:
{ >-------long a = 1, >-------.....b = 2, >-------.....c = 3; }
How to do it?
vim alignment indentation auto-indent
Dmitry Frank
source share