I am by no means a full-time software developer, but I find myself from time-to-time needing to dig into some code. While many developers use an IDE, I find IDEs overkill for my use-cases and an unnecessary dependency on my systems. I recently saw a colleague using VIM very similar to an IDE and I become intrigued. With a little help, I got everything setup and now have an easily portable IDE in an interface I frequently use: VIM. In this post, I would like to walk through the steps that were shown to me to get this all setup.
Dependencies
- VIM
- vim-pathogen — VIM plugin manager
- Tagbar — VIM plugin that gives you a nice class explorer
- NERDTree — VIM plugin that gives you really good file system navigation
- ctags — allows you to use some VIM features to navigate source code like an IDE (can use macports to install)
- cscope — allows you to use some VIM features to navigate source code like an IDE (can use macports to install)
Next Steps
Once you have everything installed and configured, the next step is to feed data into ctags and cscope. To do this, you need a script that can search for you source code. For Java, you could use something like the following:
#!/bin/bash rm -f tags find . -name "*\.java" > tagme ctags -L tagme cscope -ub -i tagme rm tagme
You should call this script when you enter your source code directory and whenever major additions/deletions of source code files occur. With this in place, you are good to go! Now you can either execute vim with the Java class you are interested in by doing:
vim -t
or from within VIM by doing:
:tag <Java_class>
Then, depending on how you configured your .vimrc file you can use the appropriate map for the TagbarToggle and/or the NERDTreeToggle. In my case, I opted for the following mapping:
nmap :TagbarToggle map :NERDTreeToggle
The only other advanced thing to leverage is VIM splits:
- ctrl-w v for a vertical split
- ctrl-w s for a horizontal
- ctrl-w plus a movement key (h/j/k/l) to move around them
I am not sure about you, but I find this setup awesome. Happy coding!
© 2015, Steve Flanders. All rights reserved.
Many students in Java write very short java programs that use args. Can this be made to work in that type of situation too?
Hey David — thanks for the comment! Can you elaborate on what you mean?