tags:

views:

268

answers:

3

The tip. The errors are "E349: No identifier unders cursor", "E433: No tags file" and "E426: tag not found: public". I feel them unrelated or I cannot understand their message. I have the code in "~/.vimrc" and pressed "F1", "F9" and "ESC". A related tip but more advanced. so how can I add Java import statements automatically in Vim?

[Added] I use Eclipse on the side but when it is down-or-slow-or-compiling-or-doning-something-stupid I use Vim. So stop here. What are the errs for?

+1  A: 

I am a dyed in the wool VI programmer, but I know to use the right tools for the right job. If you want automatic inclusion of import statements while you're coding, just use an IDE already. Eclipse is great; you can even shell out to VIM sometimes if you need to.

John Weldon
eclim is really amazing. Doesn't work well on Windows though...
wishi
+2  A: 

You might want to give Eclim a try, which provides a very nice integration of Eclipse features into Vim. In their own words:

"[Eclim] provides an Eclipse plug-in that exposes Eclipse features through a server interface, and a set of Vim plug-ins that communicate with Eclipse over that interface."

earl
+1  A: 

Cursor needs to be over an identifier

It seems like the tip requires you to position the cursor over a class name for which it will then insert the import statement. "No identifier under cursor"-error shows up when the mapping tries to use the <C-W>} command when there is no word under the cursor.

ctags

The other errors show up because it also uses the command <C-W>} which requires you to have a ctags file containing the tags for the project. That can be generated with a ctags utility. Exuberant ctags is quite nice for that purpose:

http://ctags.sourceforge.net/

Here is some information about using ctags for java (although on my system I don't have a command exuberant-ctags, it's just ctags):

http://blog.vinceliu.com/2007/08/vim-tips-for-java-2-using-exuberant.html

Tip quality

It looks like the mapping in that tip clobbers the default register, search register and changes the last change command, the jump stack, the tag stack and moves the cursor. So it's a quick'n dirty tip, not very elegant.

Heikki Naski
What are the tags? wget-mirrored-java-api, ctags created on it, type "String", pressing "^]" but it cannot find the tag for String. Would have been cool to browse java-api directly from Vim
HH
@HH: You need the source code for your version of java. It might be packaged with your JDK in a file called src.zip or you may be able to download the source somewhere. You can then unzip the code somewhere and use the tags file generated from that.
Heikki Naski