When a line becomes too long, I would like to wrap the function call with a "one argument per line" syntax:
For the example: :set textwidth=50
. Given:
long_function_name(argument_one, argument_two, argument_three, { complex: 'argument' })
I want a command, function or mapping, preferably just gq
, to turn this into:
long_function_name(
argument_one,
argument_two,
argument_three,
{ complex: 'argument' }
)
Currently, hitting gq
wraps it to:
long_function_name(argument_one, argument_two,
argument_three, { complex:
'argument'
})
Which is hard to read and messy. E.g. the Rust styleguide uses the one-arg-per-line formatting
This example is Ruby code, but I presume this hardly differs and would be the same for e.g. Rust or C; So if the Ruby-ism, the { complex: 'argument' }
is unsupported, I don't mind some manual editing afterwards, in order to fix this.
I've played around with cinoptions
as explained in this stackoverflow answer but either don't understand that feature, or fail to configure it to do what I want.
gq
is (by default) a dumb formatter. You can setformatprg
to a program of your choice, however, if you have a good ruby/rust/go/etc. formatter (an ftplugin may be an appropriate place, usingsetlocal
)gq
will useformatprg
if set?:help 'formatprg'