用了半年时间Vim了,vim的好不用我说了,用过就知道。php
使用vim写php的话,在浏览器运行便可。可是想要编译c/cpp文件的话,windows下通常都是使用ide,但是习惯了在Linux使用gcc和gdb以后,怎么舍得抛弃呢。
如何打造windows+vim+gcc+gdb的开发环境呢?很是简单:c++
如今就把我这个过程完整记录下来。编程
1,首先下载安装MinGW。
下载地址在http://sourceforge.net/projects/mingw/。这个"mingw-get-inst-20101030.exe"是边下载边安装的,下载完成即安装完成。个人安装目录是C:\MinGW。vim
2,设置环境变量。右击个人电脑,点属性->高级->环境变量。而后:windows
1) 在PATH里加入C:\MinGW\bin,记得,若是里面还有其余的变量,记得要加个分号啊,分号得在英文输入模式下输入的。
2) 新建LIBRARY_PATH变量,若是有的话,在值中加入C:\MinGW\lib,这是标准库的位置。
3) 新建C_INCLUDEDE_PATH变量,值设为C:\MinGW\include。
4) 新建CPLUS_INCLUDE_PATH变量,值为C:\MinGW\include浏览器
具体路径请根据你的MinGW选择。less
3,在你的_vimrc文件中配置编译调试选项。ide
个人我的配置以下(在_vimrc文件尾行加入):函数
“定义CompileRun函数,用来调用进行编译和运行spa
func CompileRun() exec “w” “C程序 if &filetype == ‘c’ exec “!gcc -Wl,-enable-auto-import % -g -o %<.exe” “c++程序 elseif &filetype == ‘cpp’ exec “!g++ -Wl,-enable-auto-import % -g -o %<.exe” endif endfunc “结束定义CompileRun “定义Run函数 func Run() if &filetype == ‘c’ || &filetype == ‘cpp’ exec “!%<.exe” endif endfunc “结束定义Run “定义Debug函数,用来调试程序 func Debug() exec “w” “C程序 if &filetype == ‘c’ exec “!gcc % -g -o %<.exe” exec “!gdb %<.exe” elseif &filetype == ‘cpp’ exec “!g++ % -g -o %<.exe” exec “!gdb %<.exe” endif endfunc “结束定义Debug
4,完成上面几步基本上就大功告成啦,尽情享受vim编程吧。
可能遇到的问题:
编译的时候可能会出现:
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-import)
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
uto-importing has been activated without –enable-auto-import specified on the c
ommand line.
This should work unless it involves constant data structures referencing symbols
from auto-imported DLLs.)
在编译命令中加入 -Wl,-enable-auto-import 就行啦