vim 一键编译运行c++,c,java,python, shell

linux下

" F5编译和运行C程序,C++程序,Python程序,shell程序,F9 gdb调试
" 请注意,下述代码在windows下使用会报错,需要去掉./这两个字符

"  编译和运行C
map  :call CompileRunGcc()
func! CompileRunGcc()
exec "w"
exec "!gcc % -o %<"
exec "! ./%<"
endfunc

"< F5> 编译和运行C++
map  :call CompileRunGpp()
func! CompileRunGpp()
exec "w"
exec "!g++ % -o %<"
exec "! ./%<"
endfunc
 
"  运行python程序
map  :w:!python %

"  运行shell程序
map  :call CompileRunSH()
func! CompileRunSH()
exec "w"
exec "!chmod a+x %"
exec "!./%"
endfunc

"  gdb调试
map  :call Debug()
func!  Debug()
exec "w"
exec "!gcc % -o %< -gstabs+"
exec "!gdb %<"
endfunc  


或者这样也可写:

windows下

map  :call CompileRunGcc()
func! CompileRunGcc()
    exec "w"
    if &filetype == 'c'
        exec "!g++ % -o %<"
        exec "! %<"
    elseif &filetype == 'cpp'
        exec "!g++ % -o %<"
        exec "! %<"
    elseif &filetype == 'java' 
        exec "!javac %" 
        exec "!java %<"
    elseif &filetype == 'sh'
        :!%
    endif
endfunc
"C,C++µÄµ÷ÊÔ
map  :call Rungdb()
func! Rungdb()
    exec "w"
    exec "!g++ % -g -o %<"
    exec "!gdb %<"
endfunc



你可能感兴趣的:(Linux学习,vim)