Indenting Java throw statements
From Vim Tips Wiki
(Redirected from VimTip221)
Tip 221 Previous Next Created: February 26, 2002 Complexity: intermediate Author: Alexey Marinichev Version: 6.0
I want to indent java files like this:
int x(int y, int z)
throws Exception
{
[...]
return something;
}
By default Vim will properly indent "throws" line, but following "{" will not be deindented back to the method declaration.
The following indentexpr does the trick:
let &indentexpr='getline(v:lnum)=~"^\\s*{" && getline(v:lnum-1)=~"^\\s*throws\\s" ? cindent(v:lnum)-&sw : cindent(v:lnum)'
It just checks that the current line starts with "{" and the previous line starts with "throws" and if that is the case, it subtracts one shiftwidth from the number returned by cindent.
[edit] Comments
Vim 6.1a.026 adds a more general solution to the Java indent file.
