问题
I have @Override annotation in my java code, but vim indent the next line automatically like this:
@Override
public String toString()
{
//some code
}
How can I get rid of the indent?
As far as I know, the indent file java.vim in /usr/share/vim/vim73/indent has addressed the problem, yet the problem still remains. Here's the code in java.vim:
" If the previous line starts with '@', we should have the same indent as
" the previous one
if getline(lnum) =~ '^\s*@\S\+\s*$'
return indent(lnum)
endif
回答1:
Edit:
I just tested this on version 7.3.918 with both snippets and they both work. This means that something is wrong with your vim setup. Take a look at your vimrc and see if anything is wrong.
Also look at the value returned by :set ft it should return filetype=java. If this does not happen make sure you have filetype plugin indent on in your vimrc and check to see if this fixes your problem.
Also the below snippet does not to be used because vim does this by itself in later versions.
I have this in the file ~/.vim/after/indent/java.vim which was taken from here
function! GetJavaIndent_improved()
let theIndent = GetJavaIndent()
let lnum = prevnonblank(v:lnum - 1)
let line = getline(lnum)
if line =~ '^\s*@.*$'
let theIndent = indent(lnum)
endif
return theIndent
endfunction
setlocal indentexpr=GetJavaIndent_improved()
This seems to work for indenting java annotations properly.
来源:https://stackoverflow.com/questions/16228548/how-to-remove-indent-after-annotation-in-java