How to use ctags and vim to jump to java methods

ctagsjavavim

This used to work before I upgraded my Ubuntu system:

ctags *.java
vim -t fooFunc

Which would then take me to e.g. Foo.fooFunc()

But now, vim goes to the standard "tag not found" page.

I now have to do:

vim -t Foo.fooFunc()

For it to do the right thing.

More importantly, ^] no longer works at all.

Looking at the generated tags file, I see entries like:

Foo.fooFunc Foo.java  /^    private void fooFunc() {$/

While the tags file generated by an older version of ctags would have looked like

fooFunc Foo.java  /^    private void fooFunc() {$/

so it looks like ctags is now broken.

Is there a way to revert to the old behavior? Or make vim respect the new format?

Best Answer

I am using Exuberant Ctags 5.8 and run the following script to generate a tags file for my java directory:

#!/bin/bash
# zero out any previously generated tags file
# an alternative way to achieve this is by `> tags`  
truncate --size 0 tags 
find . -name \*.java -exec ctags --append {} \;

I use find and --append because there are more than 1000 .java files in the directory.

No problems with VIM - Vi IMproved 8.0.

Related Question