History
Article Edit this page Discussion

Indenting Java throw statements

From Vim Tips Wiki

(Redirected from VimTip221)
Jump to: navigation, search

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.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Indenting Java throw statements"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation