3

As recommended by Oracle's Java Code Conventions, I try to avoid lines longer than 80 characters. For this it's of course often necessary to break lines, and the document contains some general principles for this purpose.

Here are four examples given by the style guide.

function(longExpression1, longExpression2, longExpression3,
         longExpression4, longExpression5);

var = function1(longExpression1,
                function2(longExpression2,
                          longExpression3));

longName1 = longName2 * (longName3 + longName4 - longName5)
            + 4 * longname6;

if ((condition1 && condition2)
        || (condition3 && condition4)
        ||!(condition5 && condition6)) {
    doSomethingAboutIt();
}

The indentation file often recommended doesn't seem to implement these guidelines. Is there any somewhat easy way to set up autoindent in accordance with these recommendations? In my vimrc I have set cindent and set cinoptions=(0, which cover the first two cases. Unfortunately, I couldn't find any options to realize autoindent for the other scenarios.

Any suggestions would be greatly appreciated! `

0

1 Answer 1

1

After some further research, I came across clang-format which works great with vim. I would have preferred a solution with a simple indentation file, but this works for me. The relevant options seem to be:

AlignAfterOpenBracket: Align 
AlignAfterOpenBracket: Align
BreakBeforeBinaryOperators: true
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
ColumnLimit:     80
IndentWidth:     4
TabWidth:        8

This solves the first three cases. Unfortunately, I was not able to figure out how to implement that "Line wrapping for if statements should generally use the 8-space rule" ("since conventional (4 space) indentation makes seeing the body difficult"). But this admittedly ceased to be a vim issue, so I'll ask someplace else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.