"compile c c++ file in quickfix
nmap <F4> :call DoOneFileMake()<CR>
function DoOneFileMake()
if(expand("%:p:h")!=getcwd())
echohl WarningMsg | echo "Fail to make! This file is not in the current dir! Press redirect to the dir of this file."
endif
exec "w"
call SetCompilation()
exec "make"
exec '!time ./%<'
exec "copen"
endfunction
function SetCompilation()
if &filetype=='c'
set makeprg=gcc\ %\ -o\ %<
elseif &filetype=='cpp'
set makeprg=g++\ %\ -o\ %<
endif
endfunction
截取自我自己的.vimrc
具体从哪抄来的就不知道了,
效果:

本文分享了一种在Vim编辑器中高效编译C/C++源文件的方法,通过自定义映射键和函数实现一键编译,并针对不同文件类型自动设置编译器。适用于希望提升开发效率的C/C++程序员。
766

被折叠的 条评论
为什么被折叠?



