On Fri, 12 May 2006, John Schmerge wrote:

Hi all,

 I've got a question about changing vim's indentation behavior for
c/c++:

Is it possible to get the editor to insert tabs to signify *indentation*
level, and to insert spaces to align text *after* the indentation? I've
been trying to find some sort of option that allows for this and haven't
found any sort of solution (short of creating my own c indentation file).

To explain a little bit better, the following code fragment (with tabs
replaced by '--->' and spaces replaced by backquote characters) is an
example of the indentation style that I want vim to produce:

/*
`* This is a comment note the spaces aligning the continuation lines
`*/
int main(int argc, char ** argv)
{
--->/*
--->`* note that the 2nd & 3rd parameters are aligned with spaces...
--->`* Vim indentation would insert more than a single tab on these
--->`* lines; causing a change in tab size to munge the code formatting.
--->`* This is the main thing that I want to change.
--->`*/
--->printf("This is a printout with a value(%d)\n",
--->```````25,
--->```````bl);

--->/* note the spaces inserted between the tabs and logic operators */
--->if (  (condition1 && condition2)
--->```|| (  condition3
--->``````&& condition4) )
--->{
--->--->doSomething();
--->}

--->switch (condition)
--->{
--->`case '1':
--->--->doSomething();
--->--->break;
--->`default:
--->--->break;
--->}
}

In essence, I want vim not to replace spaces by tabs, and insert spaces
instead of tabs in certain situations. Is this possible?

The answer to your question is: yes, it's possible :)

There's a catch: you need to define the "certain situations" where you
want Vim to insert spaces instead of tabs, as mentioned above.

In other words, can you define a general (and consistent) set of rules
for indentation vs. alignment that would produce the output you just
showed above?

That means, you start with an input source file, run it through a
function, and then out comes the output source file that has its
indentation (with tabs) and alignment (with spaces) determined. That
function needs to know how to do it.

Also, have a look at ":help 'smarttab'" & ":help cinoptions-values".

--
Gerald

Reply via email to