2

I currently use astyle -A8 -t8 -p -j <filename> to format the code in my C project.

Is there a way to configure my .vimrc to follow the continuation line format that the above demands? For example astyle formats the below function call:

my_function(first_arg, 
<tab>second_arg,
<tab>third_arg);

(which is the default indentation when I hit Enter) as

my_function(first_arg, 
            second_arg,
            third_arg);

I saw in cinoptions-values there was something close:

                                               *cino-+*
+N    Indent a continuation line (a line that spills onto the next)
      inside a function N additional characters.  (default
      'shiftwidth').
       Outside of a function, when the previous line ended in a
       backslash, the 2 * N is used.

        cino=             cino=+10 >
          a = b + 9 *       a = b + 9 *
              c;                      c;

But that only aligns to a specific number of spaces. Is there a way to align it like the astyle example above?

3

The option you're looking for is set cino+=(0

(N    When in unclosed parentheses, indent N characters from the line
      with the unclosed parentheses.  Add a 'shiftwidth' for every
      unclosed parentheses.  When N is 0 or the unclosed parentheses
      is the first non-white character in its line, line up with the
      next non-white character after the unclosed parentheses.
| improve this answer | |
  • This is almost exactly what I need... but is there a way to not insert a 'shiftwidth' and instead just insert aligning spaces? – Jin Nov 3 '17 at 19:42
  • Exactly as in my answer: set cino+=(0. Does this not work? – Mass Nov 3 '17 at 20:20
  • Ah I should clarify that I use tabs for C with the following: autocmd Filetype cType setlocal ts=4 sts=4 sw=4. I just tried it with spaces and that's why there's an extra 'shiftwidth'. Is there a way to make custom cinoptions? – Jin Nov 3 '17 at 20:29

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.