sponsor Vim development Vim logo Vim Book Ad

Scala Java Edit : Jump to source file associated with class name

 script karma  Rating 4/1, Downloaded by 328    Comments, bugs, improvements  Vim wiki

created by
richard emberson
script type
Then press ,g while cursor is on a class name word and
the file should open (you'll need the
source files and the path to have been set already).

Place cursor over a word and attempt to find a scala file with the give name.

The following matches are attempted:
1) Is the cursor over a full package classname (e.g., scala.collection.Map)
    If so is it over the classname (Map)
      If so open it.
    Or it is over on of the package names (collection)
      If so open the directory (scala/collection).
2) Is there a local file with the name <cword>.scala
    If so open it.
3) Is there an import statement with that file identified explicitly
    (e.g., scala.collection.Map for Map).
    If so open it.
    If "locate" is enabled, search for file scala/collection/Map.scala (in this
    example). If found, open it.
4) Is it a file located in "$JAVA_HOME/src/scala/lang/" directory
    If so open it.
5) Is there an import statement with that file identified implicitly.
    (e.g., scala.collection.* for Map).
    If so open it.
    If "locate" is enabled, search for file scala/collection/Map.scala (in this
    example). If found, open it.
6) Its possible we are in a junit directory or is some parallel directory
    structure so that our current file has the same package statement
    value as some source files in a different directory. This attempt takes
    the package statement value, creates a directory plus scala file from
    it and first looks through the scala path and if not found there,
    does a "locate" searching for the file.

Also, can be configured to work with Java files (or with both Scala
and Java source files).
install details
Suggested stuff to add to your ~.vimrc:

" Set my Leader character
let mapleader = ","

" use locate command
let g:javae_locate_cmd = "locate"
source $HOME/vim/scalajavaedit.vim

" Java Stuff
   \",$HOME/java/xerces/xerces/src" .
   \",$HOME/java/xerces/xalan/src" .
   \",$HOME/java/jboss/jboss" .
   \",$HOME/java/jakarta/commons-lang/src/java" .
   \",$HOME/java/jakarta/commons-collections/src/java" .
" Note that for Java, only search for files with the 'java' suffix
" goto
autocmd FileType java map <Leader>g :call EditSource('e',['java'],=,JAVASOURCEPATH)<CR>
" horizontal
autocmd FileType java map <Leader>h :call EditSource('sp',['java'],=,JAVASOURCEPATH)<CR>
" vertical
autocmd FileType java map <Leader>v :call EditSource('vsp',['java'],=,JAVASOURCEPATH)<CR>

" if you want to debug, comment out above line and uncomment below line
"map <Leader>g :debug:call EditSource('e',JAVASOURCEPATH)<CR>

" Scala Stuff
   \",$SVN_HOME/project1/src/main/scala" .
   \",$SVN_HOME/project1/src/test/scala" .
   \",$SVN_HOME/project2/src/main/scala" .
   \",$SVN_HOME/project2/src/test/scala" .

" Note that for Scala, search for files with the 'scala' and
"    then 'java' suffixes
" goto
autocmd FileType scala map <Leader>g :call EditSource('e',['scala', 'java'],SCALASOURCEPATH)<CR>
" horizontal
autocmd FileType scala map <Leader>h :call EditSource('sp',['scala', 'java'],SCALASOURCEPATH)<CR>
" vertical
autocmd FileType scala map <Leader>v :call EditSource('vsp',['scala', 'java'],SCALASOURCEPATH)<CR>

End Suggested stuff to add to your ~.vimrc:

One can of course, define more than one SOURCEPATH search variable and
have different mappings to envoke the different search paths.
When porting Java code to Scala (and keeping the same package names for
the classes), I define a second search path and key map bindings
allowing me to jump from the ported Scala source file to
the Java source file which was the basis of the port.

Your java source path, of course, be different.

Many java src tar files untar into directories with include not only
the component name, but also a version number (e.g., xerces has source
directory xerces-2_6_2) - make symbolic link,
ln -s xerces-2_6_2 xerces
and your vimrc will not have to be changed everytime you get a new

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
scalajavaedit.vim 1.6 2011-03-18 7.2 richard emberson Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo