windows下gVim运行c、c++、python程序

首先声明,本帖只讲源程序的编译和执行怎么实现,不讲一些好用的插件。

如果你电脑上安装了visual stdio的IDE,则参考这个帖子:https://www.cnblogs.com/zhuyp1015/archive/2012/06/16/2552269.html

如果只是安装了vc++ 6.0,则看下面:

很简单,一共两步:

1、创建环境变量

要创建三个环境变量,相应的路径对应你vc++ 6.0或是python的安装目录即可:

1)PATH:一般你的环境变量中是已经有的, 所以直接追加上

F:\vc++6.0\Microsoft Visual Studio\Common\IDE\IDE98;F:\vc++6.0\Microsoft Visual Studio\VC98\Bin;F:\vc++6.0\Microsoft Visual Studio\Common\MSDev98\Bin;F:\python\

2)INCLUDE:F:\vc++6.0\Microsoft Visual Studio\VC98\Include

3)LIB:F:\vc++6.0\Microsoft Visual Studio\VC98\Lib

2、修改vimrc文件

在文件中追加以下内容(直接复制粘贴即可):

func! CompileCode()
exec "w"
if &filetype == "c"
   exec "!cl %<.c "
elseif &filetype == "cpp"
   exec "!cl %<.cpp "

elseif &filetype == "python"
  exec "!python %<.py"

endif
endfunc

" 运行可执行文件
func! RunCode()
exec "w"
if &filetype == "c" || &filetype == "cpp" || &filetype == "haskell"
exec "! %<.exe"
elseif &filetype == "python"
exec "!python %<.py"
endif
endfunc

" Ctrl + C 一键保存、编译
map :call CompileCode()
imap :call CompileCode()
vmap :call CompileCode()

" Ctrl + R 一键保存、运行
map :call RunCode()
imap :call RunCode()
vmap :call RunCode()

完成上述操作之后,你的gvim应该就可以运行c、c++和python程序了,具体操作是在gvim中打开你的源程序之后,在命令模式下按CTRL+C即可编译你的c程序,ctrl+r即可运行你的程序了。

效果如下:

c程序运行结果:

windows下gVim运行c、c++、python程序_第1张图片

python程序运行结果:

windows下gVim运行c、c++、python程序_第2张图片

 

你可能感兴趣的:(gVim和vim)