vimrc 一键编译程序

set nu
syntax on
set autoindent
set cindent
set smartindent
set tabstop=3
set softtabstop=3

map <F5> :call CompileRunGpp()<CR>  
func! CompileRunGpp()  
        exec "w"  
        exec "!g++ %"  
        exec "! ./a.out"  
        endfunc  
~                       

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

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

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

" <F5> 运行python程序
map <F5> :w<cr>:!python %<cr>

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

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

 

posted @ 2012-10-17 12:21  Levi_随云  阅读(274)  评论(0编辑  收藏  举报