Sumit
Sumit

Reputation: 2264

Formatting multiple line statement in vim

In vim a long statements like

 if ( (image == null) || (image.getFileHash() == null) || (image.getFileImage() == null) )

gets indented like this when I hit an enter before the second OR

if ( (image == null) || (image.getFileHash() == null)
        || (image.getFileImage() == null) ) {

is there a way to set vim to indent it like

if ( (image == null) || (image.getFileHash() == null)
    || (image.getFileImage() == null) ) {

i.e., aligning it with the column after ( of the first previous line.

With dash-tom-bang's help was able to solve a part of the problem. However, now the curly brackets are not aligned as expected if { starts on the same line.

if ( (image == null) || (image.getFileHash() == null) ||
     (image.getFileImage() == null) )
{

}

if ( (image == null) || (image.getFileHash() == null) ||
     (image.getFileImage() == null) ) {

     }

Upvotes: 1

Views: 509

Answers (1)

dash-tom-bang
dash-tom-bang

Reputation: 17843

The setting that controls this is cinoptions, see :help cinoptions-values.

Add this to your .vimrc to align with the most local unclosed parenthesis. (You can give extra indent in spaces by giving a different number, including negatives. You can indent N tabstops by using Ns.)

set cinoptions=(0

The default value is 2s, which would indent two tabs past the open paren; hopefully this is what you're seeing. :)

Upvotes: 3

Related Questions