m.divya.mohan
m.divya.mohan

Reputation: 2330

vim indent: align function arguments

The default alignment in vim (using "=") aligns my code as:

void my_loooong_function (int arg1,
        int arg2,
        int arg3
        )

However, I wish to align with all arguments starting at same line, as:

void my_loooong_function (int arg1,
                          int arg2,
                          int arg3
                         )

How can this be done?

Upvotes: 12

Views: 4988

Answers (2)

Prince Goulash
Prince Goulash

Reputation: 15715

To make == work as you wish, you need to set cinoptions appropriately:

:set cino+=(0

Full documentation of the possible values can be found via :help cinoptions-values, and in particular :help cino-( to control the indentation inside unclosed parentheses.

The setting will also affect the autoindent behaviour (for example, when you enter a carriage return after opening a bracket).

This can, of course, be added to your vimrc or an ftplugin to automatically set this value for certain filetypes.

Upvotes: 22

kev
kev

Reputation: 161664

Try vim plugin Tabular:

:Tabularize /\v[( )](int|$)

Tutorial: http://vimcasts.org/episodes/aligning-text-with-tabular-vim/

Upvotes: 6

Related Questions