Saturday, October 29, 2011

Re: Formatting C++ files

I assume that not every function in the headers is called "AFunction"
with void return type, so this is a little more liberal than precisely
what you stated. It will apply to any line that has some whitespace,
followed by one or more words (the return type, including '*' for
pointer types), followed by a function name and its argument list.

:%s/\v^\s+([a-zA-Z_* ]+)\s+(\*?)(\s*\w+\(.*\);)$/\t\t\1\2\t\t\t\t\t\t\t\t\3/

It's perhaps a little more complex than it needs to be, because it
handles cases where you might have something like this:

int *my_function();

where the '*' is considered part of the return type, not the function
name, and you would presumably want it separated from the function name
when you convert the whitespace.

There may be corner cases in your header files that I didn't think of,
so if this doesn't apply to any of the lines that you need converted,
then you may need to tweak it. Or you can post the problematic lines
here and we can give you additional help.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: