I have the following options setup for C++ and Python development in vim:
autocmd BufEnter *.cpp setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=80 noexpandtab cindent cinoptions=:0,l1,t0,g0,(0
autocmd BufEnter *.py setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=79 expandtab cindent cinoptions=:0,l1,t0,g0,(0
In Python, when I am manually creating continuation lines (i.e. to keep code from spilling past a certain column number), auto-indenting and auto-alignment (i.e. visual selection, g,q), I encounter very different behavior for Python versus C++ code. For example:
Example: Works in C++ and Python Code.
val = some_class.some_function(this_is_a_variable_1, this_is_a_variable_2, this_is_a_variable_3, this_is_a_variable_4)
Becomes:
val = some_class.some_function(this_is_a_variable_1, this_is_a_variable_2,
this_is_a_variable_3, this_is_a_variable_4)
However, there is different behavior for C++ and Python code with the following example(s):
Example: Python Behavior (Desired).
If I insert a newline after the bracket (
character, the following continuation format occurs:
val = some_class.some_function(this_is_a_variable_1, this_is_a_variable_2, this_is_a_variable_3, this_is_a_variable_4)
Becomes:
val = some_class.some_function(
this_is_a_variable_1, this_is_a_variable_2, this_is_a_variable_3,
this_is_a_variable_4)
Example: C++ Behavior (Not Desired).
If I insert a newline after the bracket (
character, the following continuation format occurs:
val = some_class.some_function(this_is_a_variable_1, this_is_a_variable_2, this_is_a_variable_3, this_is_a_variable_4)
Becomes:
val = some_class.some_function(
this_is_a_variable_1, this_is_a_variable_2,
this_is_a_variable_3, this_is_a_variable_4)
This behavior is desirable for function prototypes/declarations, but not for general code.
Question
How do I get C++ auto-indentation/auto-formatting to behave the same as Python does (given the above examples) in VIM (i.e. have the continuation line use a single-tab or double-tab, rather than aligning with the opening bracket)?
Thoughts/Work So Far
Since the above indentation for C++ is only used for function declarations/prototypes, maybe I could write a macro to apply that specific indentation to a visual selection, and disable that formatting option in general.
Thank you.