用vim编辑C语言
1,用gvim 编译C 语言时,请先下载mingw;
2 ,设置环境变量。右击我的电脑,点属性->高级->环境变量。然后:
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 选择。
3 ,在你的_vimrc 文件中配置编译调试选项。
配置如下(在_vimrc 文件尾行加入):
"定义CompileRun 凼数,用来调用迚行编译和运行
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
"注意上面的引号必须都为英文输入下的,因为偷懒没有改过来;
可能遇到的问题:
编译的时候可能会出现:
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 就行啦
为方便编辑C 语言,可以去vim 官方网站下载c.vim 插件,然后将其解压到vim 下
的vimfiles 里即可;最后当你打开隐藏的菜单栏是会看到C/c++的选项。