[vim]一键编译运行c程序
主要用来编译C语言的小程序,多文件IDE比较方便点。 我的vimrc
有error时弹出quickfix窗口
有warning时,运行编译结果,且弹出quickfix窗口
没有任何提示时,直接运行
function! CompileFile()
if &filetype == 'c' || &filetype == 'cpp'
if &filetype == 'c' | set makeprg=gcc\ -std=c99\ -Wall\ -Wconversion\ -o\ %<.exe\ %
else | set makeprg=g++\ -o\ %<.exe\ %
endif
silent exe "make"
if getqflist() == [] "compile correct and no warning
let l:flag = 0 | silent exe "ccl" | exe "!%<.exe"
else
for l:inx in getqflist()
for l:val in values(l:inx)
if l:val =~ 'error' | let l:flag = 1 | break
elseif l:val =~ 'warning' | let l:flag = 2
else | let l:flag = 0
endif
endfor
if l:val =~ 'error' | break | endif
endfor
endif
if l:flag == 1| exe "cw"
elseif l:flag == 2
let l:select = input('There are warnings! [r]un or [s]olve? ')
if l:select == 'r' | exe "!%<.exe" | exe "cw"
elseif l:select == 's' | exe "cw"
else | echohl ErrorMsg | echo "input error!"
endif
else | exe "cw"
endif
elseif &filetype == 'python'
exe "!%<.py"
else
echohl ErrorMsg | echo "This filetype can't be compiled !"
endif
echohl None
endfunction
Good Good Study! Day Day Up!