I am a Python programmer using Vim. When writing a long function call, it often exceeds the width of my document:
a_long_python_function(with_some, additional, arguments, kwarg1=kwarg1, kwarg2=kwarg2, kwarg3=kwarg3)
In the end, I would like to achieve a formatting like the following
a_long_python_function( with_some, additional, arguments, kwarg1=kwarg1, kwarg2=kwarg2, kwarg3=kwarg3 )
where all the arguments get shifted exactly once more than the line with the function call and the closing bracket is at the same indentation level as the call. For the arguments in between, I would like to have a line break between keyword and non-keyword arguments, though this is optional. I use tabs rather than spaces. Function calls that do not exceed
textwidth should not be changed.
The function that currently does Python indentation for me was delivered directly with Vim. I read it and thought that I would be able to change it to my needs but it seems I am still not experienced enough in Vim script (I don't give the code here because it is lengthy. Interested readers may check
$VIMRUNTIME/autoload/python.vim. That's where I found it).
Ideally, I would like the re-formatting to take place while I type and as soon as the number of characters in a line exceeds
textwidth, but it would be also okay if I was able to auto-format things properly later, e.g. by using