4

I need to respect a coding style with 4 spaces tabulations and I want to fit with the 80 columns rule. I get then the case where some function need their parameters written on several line :

int very_long_function_name (int long_param_name_1, int long_param_name_2)

I want it to be changed into

int very_long_function_name (int long_param_name_1,
    int long_param_name_2)

But when I press = to autoindent, I get

int very_long_function_name (int long_param_name_1,
        int long_param_name_2)

I set these values in my .vimrc :

set tabstop=4
set shiftwidth=4
set expandtab

What am I missing ?

  • 3
    This is controlled by the cinoptions option, you should have a look at :h 'cinoptions' and more precisely at :h cinoptions-values and :h cino-(. – statox Oct 17 '16 at 13:35
  • Thank you @statox ! I solved my problem by setting adding cinoptions=(4,W4. These options are exactly what I wanted. – Meinew Oct 17 '16 at 14:39
  • Glad I could help, I made it an answer :-) – statox Oct 17 '16 at 14:59
6

From :h cinoptions you read:

The 'cinoptions' affect the way 'cindent' reindents lines in a C program.
See cinoptions-values for the values of this option

From :h cinoptions-values:

The 'cinoptions' option sets how Vim performs indentation.  The value after
the option character can be one of these (N is any number):
    N   indent N spaces
    -N  indent N spaces to the left
    Ns  N times 'shiftwidth' spaces
    -Ns N times 'shiftwidth' spaces to the left

And finally :h cino-( and :h cino-W tell us that set cino=( defines the behavior that the indentation should follow when it handles text between some parentheses.

Here set cinoptions=(4,W4 tells vim:

  • When in unclosed parentheses, indent N characters from the with the unclosed parentheses.
  • When in unclosed parentheses and the unclosed parentheses is the last non-white character in its line and it is not the closing parentheses, indent the following line N characters relative to the outer context (i.e. start of the line or the next unclosed parentheses).

Which does the trick as @Meinew noted in the comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.