1

Is there any autoformatter plugin for vim that support customized style? Like, adding space after parentheses, place curly brackets in current line and something like that?

What I want to achieve is a customized auto format, so I can format my code like this:

void function () {
    cout << "This format" << endl;
}

Instead of like this:

void function ()
{
    cout << "Not this format" << endl;
}

I've installed vim-autoformat. It's automated format is like the second style. So, is there any vim autoformatter that can be customized?

3
  • Better a) detail the question a bit more (I suppose you are speaking of C code formatting? or what? Can you give an example? What have you tried?) and b) better ask it on vi.stackexchange.com
    – Rmano
    Mar 25, 2015 at 9:13
  • Updated. And sorry, I didn't know vim has it's own stackexchange.
    – Mas Bagol
    Mar 25, 2015 at 9:19
  • 1
    @BagolDaplun Vi and Vim is relatively new, but questions still remain on-topic here as well.
    – muru
    Mar 25, 2015 at 9:28

1 Answer 1

1

The vim-autoformat plugin uses astyle to perform the indentation, and astyle supports a variety of indentation styles. The one you are looking for maybe close to the K&R or Java styles. Match your preferred style to one in this Wikipedia article, and to the corresponding options for astyle. Then add to your .vimrc, for example using the One True Brace Style:

let g:formatprg_c = "astyle"
let g:formatprg_args_c = " --style=1tbs "
2
  • I see. Is there any list of available format there? The site doesn't seems provide a complete list.
    – Mas Bagol
    Mar 25, 2015 at 9:35
  • @BagolDaplun I don't know, but I think all the styles mentioned in the astyle manpage are covered by the Wiki article, so a more complete list wouldn't be of much use anyway.
    – muru
    Mar 25, 2015 at 9:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .