In my IDE (webstorm) I have configured an ext开发者_如何学JAVAernal tool to run ant like so:
ant myTarget -DfileNoExt="$FileNameWithoutExtension$"
the $FileNameWithoutExtension$
is expanded by the IDE when the command is run.
I am transitioning to using Vim. I am a Vim n00b.
How do I do the same with Vim (MacVim specifically)?
Vim will expand %
as the current file. You can use modifiers on it (see :help filename-modifiers
). You can tell vim to use ant as your make program:
compiler ant
setlocal makeprg=ant\ myTarget\ -DfileNoExt=\"%:t:r\"
Now you can use :make
to build your current file. You should get build errors in your quickfix (view it with :copen
).
You probably want to put the above script into a file ~/.vim/after/ftplugin/java.vim
. That will load it for every java file you open.
Note that if you want to use different targets, :make
will pass all arguments to ant. So :make otherTarget
will execute ant myTarget -DfileNoExt="file" otherTarget
.
you can map either Hotkey or Your own key-sequence in vim.rc(not sure in mac, should have similar resource file)
add this line to your vim resource file:
imap <F5> <ESC><ESC>:!ant mytarget -Dfilenoext=\"%<\"
which means when you editing the source code, press F5 will run your ant tool for more, you can read http://vim.wikia.com/wiki/Compile_Java_with_Sun_JDK_javac and http://www.vim.org/scripts/script.php?script_id=155
精彩评论