Reputation: 400
I want to somehow indent my java code within parenthesis just like it'd be within braces. Here a dummy example of how it could look like:
public String hello(
String really,
String looong,
String listOf,
Optional<String> params
) {
return params.map((p) -> "Do something with the value " + p).orElse("world");
}
I was trying to solve it using cinoptions
, but seems like there is no such an option. I don't want to end up writing custom identexpr
for java.
Upvotes: 0
Views: 188
Reputation: 400
Well, since I couldn't find a simple solution for that, I've overridden the indentexpr for java by putting the following code to ~/.vim/after/indent/java.vim
:
setlocal indentexpr=GetMyJavaIndent()
function GetMyJavaIndent()
" When the line starts with a ), try aligning it with the matching (
if getline(v:lnum) =~ '^\s*)'
call cursor(v:lnum, 1)
silent normal! %
let lnum = line('.')
if lnum < v:lnum
return indent(lnum)
endif
endif
return GetJavaIndent()
endfunction
Upvotes: 1