I often find myself having to reformat C++ function arguments and template parameters to occupy individual lines rather than being on the same line. Here are a few examples.
Turn this
template <typename T>
std::enable_if_t<some_type_trait<T>, int> foo(const T&);
into this
template <typename T>
std::enable_if_t<
some_type_trait<T>,
int
> foo(const T&);
Turn this
double inner_product(const std::array<double,3>& a, const std::array<double,3>& b);
into this
double inner_product(
const std::array<double,3>& a,
const std::array<double,3>& b
);
Does a plugin that does that already exist? If not, can someone help me write a vim function for it?
What I'd like to do is put the cursor inside the outer parentheses or angle brackets and press a key combination to reformat the arguments to individual lines. Not recursively. Just the top level. The number of arguments can be arbitrary. And, as I tried to illustrate in the second example, there may be additional commas that don't separate arguments.
So, a bit similarly to how vim-surround
works, except, instead of replacing the type of brackets, I want the code inside the brackets reformatted.