A Vim importer for Java
Vim script
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



A Java importer and Javadoc lookup tool for VIM (for OSX/Linux)


  1. Automatically create an import for a Java class under the cursor (and add to the imports list in sorted order).
  2. Open the javadoc for the Java class under the cursor


For imports, you can specify three locations for Vimporter to look:

  1. Javadocs
  2. Directories
  3. Jars

You can get Oracle's javadocs for Java here: http://www.oracle.com/technetwork/java/javase/downloads/index.html#docs


Clone the github directrory into ~/.vim/plugin

cd ~/.vim/plugin
git clone git://github.com/Kashomon/vimporter.git

Add the following your .vimrc, replacing /absolute/path/... to the directories/jars you want to specify:

let g:vimporter_java_roots =  [   
\ '/absolute/path/to/javadocs/',
\ '/absolute/path/to/project_directory/src/',
\ '/absolute/path/to/jar/MyJar.jar',
\ '/absolute/path/to/multiplejars/*.jar' ]

" AutoImporter
nmap ;j :call Vimporter_AutoImportSorted() <CR>

" Doc-Lookup 
nmap ;i :call Vimporter_LibLookup() <CR>

You can of course change these key-mappings to your favorite hotkey.

Sorting Order

Vimporter puts imports into the following order:

  1. Static imports
  2. Project imports
  3. Misc org/com/etc imports
  4. Java/Javax imports


Vimporter lets you specify your top level package name to help sorting. This package name will always be sorted to the top (after static imports).

" e.g., 'com.apache', 'com.google', 'org.joda';  default = 'auto'
let g:vimporter_org_name = "auto" 

Vimporter allows fuzzy-searching for imports. Thus, if you search for String, you will get results that contain String, StringBuffer, AttributedString, etc.

" 0 or 1; default = 0
let g:vimporter_fuzzy_search = 1 

Vimporter also comes with a special field that allows you to add additional imports. This is useful if you want to specify project-specific dependencies (see Advanced Vimporting below).

let g:vimporter_add_roots = [] 

Other Functions and Features

Just do importing without sorting:

nmap ;e :call Vimporter_AutoImport() <CR>

Just do the sorting without importing:

nmap ;r :call Vimporter_SortImports() <CR>

Advanced Vimporting: Project-Specific Dependencies

Typically, the dependencies we use will depend on the project we're working on, and it's silly to search all the various jars and directories every single time.

To accomplish setting project-specific dependencies, you can use a tool called Vild.vim. After installing Vild, set a new field to initialize the extra dependency locations. We might as well throw in the root name of our project (for sorting purposes) while we're at it =).

#... other fields ... 
proj_root: "/path/to/myprojects/root/dir/", "/path/to/my/jar/dir/*.jar"
set_vimporter_res: let g:vimporter_add_roots = [] | let g:vimporter_add_roots = [ $vild:proj_root ]
set_vimporter_proj_name: let g:vimporter_org_name = "com.vild"

Then, we just need to add somes lines in the .vimrc

au BufRead,BufNewFile *.java silent call Vild_Execute("set_vimporter_res")
au BufRead,BufNewFile *.java silent call Vild_Execute("set_vimporter_proj_name")


  1. Add caching
  2. Be able to change the sorted order
  3. Ensure that vimporter works for all of OSX/Linux/Windows