写单个程序,如果每次都自己输入:set makeprg=gcc\ .......什么的就太麻烦了.所性自己定义快捷键.当然,大程序就用makefile了.这里只是为了方便下:
---------------------------------------------------------------------------------------------------------------------
,<F7>编译 ,<F8>运行 ,<F9>带参运行
举例:写文件foo_001.c 则make成可执行文件001 .如果有参,文件应是:foo_001.in 则输出foo_001.out
分隔符是下划线,稍微看下就可以随自己个性修改使用
----------------------------------------------------------------------------------------------------------------------
nmap <leader><F7> :call Gcc_make()<cr><cr>
nmap <leader><F8> :call Gcc_run()<cr><cr>
nmap <leader><F9> :call Gcc_run_infile()<cr><cr><cr>
function Gcc_run()
exec "! mv %:r `echo %:r | cut -d'_' -f2`"
exec "!./`echo %:r | cut -d'_' -f2`"
endfunction
function Gcc_run_infile()
exec "! mv %:r `echo %:r | cut -d'_' -f2`"
exec "!./`echo %:r | cut -d'_' -f2` < %:r.in > %:r.out"
exec "!cat ./%:r.out"
endfunction
function Gcc_make()
exec "w"
let s:input_file = expand("%") . "\\"
let s:output_file = expand("%:r")
exec "set makeprg=gcc\\\ -g\\\ -Wall\\\ " . s:input_file "-o\\\ " . s:output_file
exec "make"
endfunction