第一种方法去VIM官网下个CVIM插件(http://www.vim.org/scripts/script.php?script_id=213)应该是这个地址,不是的话,自己去VIM官网输入CVIM关键字搜索直接解压到你的.vim文件夹中(就是专门放VIM插件的文件夹)然后命令如下(只针对C和C++文件,其他文件无效):F9 compile and linkAlt-F9 write buffer and compileCtrl-F9 run executableShift-F9 set command line argumentsShift-F2 switch between source files and header files第二种方法(你可以自己加入java之类的一次编译运行,很简单)在vim的配置文件中加入:" 编译C源文件fun! CompileGcc() exec "w" let compilecmd="!gcc -Wall -ansi -pedantic -std=c99 " let compileflag="-o %<" exec compilecmd." % ".compileflagendfunc " 编译C++源文件fun! CompileCpp() exec "w" let compilecmd="!g++ -g -Wall -pedantic -std=c++98 " let compileflag="-o %<" exec compilecmd." % ".compileflagendfunc " 根据文件类型自动选择相应的编译函数func! CompileCode() exec "w" if &filetype == "c" exec "call CompileGcc()" elseif &filetype == "cpp" exec "call CompileCpp()" endifendfunc " 运行可执行文件func! RunResult() exec "w" if &filetype == "c" exec "! %<" elseif &filetype == "cpp" exec "! %<" endifendfunc " <F7>一键保存、编译map <F7> :call CompileCode()<CR>imap <F7> <ESC>:call CompileCode()<CR>vmap <F7> <ESC>:call CompileCode()<CR> " <F5>一键保存、运行map <F5> :call RunResult()<CR>imap <F5> <ESC>:call RunResult()<CR>vmap <F5> <ESC>:call RunResult()<CR>
VIM 一键编译
时间: 2024-10-12 13:47:47