Compiling Java code in Vim more efficiently

后端 未结 5 1311
鱼传尺愫
鱼传尺愫 2021-01-30 03:34

I come from an Eclipse background, but I love Vim as a text editor. I\'m currently experimenting with Vim as a Java IDE. Currently I do this to compile:

! javac          


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 04:03

    if you don't use any package in your java class, then

    //compile
    :!javac %
    
    //run
    :!java -cp %:p:h %:t:r
    

    map F5 in the .vimrc file to automate the build

    map  :call CompileRunGcc()
    func! CompileRunGcc()
    exec "w"
    if &filetype == 'c'
    exec "!gcc % -o %<"
    exec "!time ./%<"
    elseif &filetype == 'cpp'
    exec "!g++ % -o %<"
    exec "!time ./%<"
    elseif &filetype == 'java'
    exec "!javac %"
    exec "!time java -cp %:p:h %:t:r"
    elseif &filetype == 'sh'
    exec "!time bash %"
    elseif &filetype == 'python'
    exec "!time python2.7 %"
    elseif &filetype == 'html'
    exec "!firefox % &"
    elseif &filetype == 'go'
    exec "!go build %<"
    exec "!time go run %"
    elseif &filetype == 'mkd'
    exec "!~/.vim/markdown.pl % > %.html &"
    exec "!firefox %.html &"
    endif
    endfunc
    

提交回复
热议问题