How to use ctags and vim to jump to java methods
Solution 1
I use Universal Ctags with the command
ctags --languages=java -R ./src
I was confused at first because a different version of ctags comes preinstalled on osx. Turns out I first had to replace it with universal-ctags
brew install --HEAD universal-ctags/universal-ctags/universal-ctags
Solution 2
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 videos on Youtube
Edward Falk
Kernel engineer. Currently at Adobe, formerly Apple, Cyanogen, Amazon, Palm, Google, Sun Merge keep
Updated on September 18, 2022Comments
-
Edward Falk over 1 year
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?
-
FDinoff over 9 yearsJust some guesses. Make ctags is exuberant ctags. Check to see if you have a
~/.ctags
file. If you do check to see what flags you have enabled by default. -
Dmitry Frank over 9 yearsShow us output of
ctags --version
-
Edward Falk over 9 yearsctags (GNU Emacs 23.3) Copyright (C) 2011 Free Software Foundation, Inc. This program is distributed under the terms in ETAGS.README
-
Edward Falk over 9 yearsAlso, there is no ~/.ctags file
-