When indenting java code with annotations, vim insists on indenting like this:
@Test public void ...
I want the annotation to be in the same column as the method definition but I can’t seem to find a way to tell vim to do that, except maybe using an indent expression but I’m not sure if I can use that together with regular cindent.
edit: The filetype plugin was already turned on I just got a bit confused about indenting plugins. The accepted answer may be a bit hackish but works for me as well.
Edit: I cannot delete my own answer because it has already been accepted, but @pydave’s answer seems to be the better (more robust) solution.
You should probably be using the indentation file for the java FileType (instead of using cindent) by setting
filetype plugin indent on.That said, the indentation file coming with the Vim 7.1 from my linux distribution (looking at the current vim svn this is still true for 7.2) doesn’t account for annotations yet. I therefore copied
/usr/share/vim/vim71/indent/java.vim(see https://vim.svn.sourceforge.net/svnroot/vim/branches/vim7.1/runtime/indent/java.vim) to~/.vim/indent/java.vimand added the following lines right before the end:I’m not sure if this breaks any of the other indentations, but it works for me.