Vim and Cream
I downloaded and installed Vim 7.0 and Cream. I wanted to use Vim for editing, compiling and running the exercises in Core Java(TM) 2, Volume I--Fundamentals (7th Edition) which I checked out from the Johnson County library. I'm pretty good at Java, but, with no formal training, and never having been on a team of Java programmers, I'd like to polish my basic skills to avoid simple mistakes.
I can't recommend Cream to Vi users. It takes away the "advanced" colon commands, among other things, turning Vim into a pure GUI text editor. Well, I want to start work, not climb another learning curve. The book recommends EMACS, whihc I know is cool, but not from personal experience.
I also found JavaRun.vim, so I could compile with F9 and run with F5. I had to modify it slightly to work with javac, not jikes, and to match my setup. It is then placed in the C:\Program Files\vim\vim70\plugin directory. Here is the result:
I can't recommend Cream to Vi users. It takes away the "advanced" colon commands, among other things, turning Vim into a pure GUI text editor. Well, I want to start work, not climb another learning curve. The book recommends EMACS, whihc I know is cool, but not from personal experience.
I also found JavaRun.vim, so I could compile with F9 and run with F5. I had to modify it slightly to work with javac, not jikes, and to match my setup. It is then placed in the C:\Program Files\vim\vim70\plugin directory. Here is the result:
" JavaRun.vim
" Version 0.2
" Kendrew Lau
"
" Script to save, compile, and run the Java program in current buffer.
" The saving and compilation are only done if necessary.
" Some abbreviations for Java programming are added, e.g.
" psvm for "public static void main(String[] args) { }"
" cl for class
" fi for final
" (This is inspired by Netbeans)
" See the end of this script for the list of abbreviations.
"
" Also, save and run for Python, Perl, Ruby, Tcltk, and Clisp file.
"
" To use it, source this script and do the command :Run [arg...]
" where arg are optional arguments to the Java program to run
" Alternatively, just pressto run without arguments.
"
function! JavaRun(...)
update
let e = 0
if getftime(expand("%:r") . ".class") < getftime(expand("%"))
make
let e = v:shell_error
endif
if e == 0
let idx = 1
let arg = ""
while idx <= a:0
execute "let a = a:" . idx
let arg = arg . ' ' . a
let idx = idx + 1
endwhile
execute "!java " . expand("%:r") . " " . arg
endif
endfunction
function! ProgRun(...)
update
let e = 0
let ext = expand("%:e")
if ext == "java" && getftime(expand("%:r") . ".class") < getftime(expand("%"))
make
let e = v:shell_error
endif
if e == 0
if exists("g:runprogstring")
execute "!" . g:runprogstring
else
let idx = 1
let arg = ""
while idx <= a:0
execute "let a = a:" . idx
let arg = arg . ' ' . a
let idx = idx + 1
endwhile
cd %:p:h
if ext == "java"
execute "!java " . expand("%:r") . " " . arg
elseif ext == "py"
execute "!python " . expand("%") . " " . arg
elseif ext == "pl"
execute "!perl " . expand("%") . " " . arg
elseif ext == "rb"
execute "!ruby " . expand("%") . " " . arg
elseif ext == "tcl"
execute "!tclsh " . expand("%") . " " . arg
elseif ext == "lisp"
execute "!clisp " . expand("%") . " " . arg
endif
cd -
endif
endif
endfunction
set shellpipe=>\ %s\ 2>&1
compiler javac
set errorformat=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
" set makeprg=jikes\ +E\ %
" set errorformat=%f:%l:%v:%*\\d:%*\\d:%*\\s%m
command! -nargs=* JavaRun call JavaRun()
command! -nargs=* Run call ProgRun()
if maparg("") == ""
map:Run
endif
if maparg("") == ""
map:make "%"
endif
iab psvm public static void main(String[] args) {
}
iab sout System.out.println();
iab serr System.err.println();
iab pr private
iab pe protected
iab pu public
iab ex extends
iab bo boolean
iab ab abstract
iab cl class
iab st static
iab fi final
iab ir import
iab re return
iab sw switch
iab Ob Object
iab Ex Exception
iab En Enumeration
iab Gr Graphics
Labels: Editors, General Programming, Java, Vi

0 Comments:
Post a Comment
<< Home