您的位置:首页 > 编程语言 > C语言/C++

在vim中调用vc编译并执行c++

2010-12-18 17:45 295 查看
本文提供一种方法, 可以在vim中按F5键来让cl编译并执行当前正在编辑的c++代码. 这样在写一些简单的测试代码的时候, 只要用vim编辑一个文件就可以开始工作, 不需要打开vc创建一个工程了, 比较方便:

1. 首先需要创建一个批处理文件, 命名为compile_cpp.bat

@echo off
rem        Author: orit
rem Last-Modified: 2009-10-14
rem       Created: 2009-10-14
rem  Introduction: %1 - compiled file.
set vc_path=c:/Program Files/Microsoft Visual Studio 9.0/VC/bin
set output_file=_temp_output_.exe
set compile_option=/w /Fe%output_file%
echo ====================================================
echo                         Compile......
echo ====================================================
if exist %output_file% (del %output_file%)
call "%vc_path%/vcvars32.bat"
call "%vc_path%/cl.exe" %compile_option% %1
rem Clear screen if no ERROR.
if exist %output_file% (cls) else (goto end)
echo ====================================================
echo                             Output
echo ====================================================
call %output_file%
rem Clear temporary files.
del %output_file%
del *.obj
:end


根据自己vc安装的路径和版本不同, 需要修改vc_path.

[b]2. 将 compile_cpp.bat 所在目录添加到系统搜索路径中[/b]



[b]3. 修改vim的配置文件vimrc, 在其中添加:[/b]

[b]
autocmd FileType cpp map <F5> <Esc>:w!<CR>:!compile_cpp.bat %<CR>
[/b]



[b]这样在vim中按下F5键就可以编译执行当前正在编辑的c++代码了.[/b]

[b]本文转自:[/b]http://orit7.blogbus.com/logs/59646465.html

在此向原作者致谢。这是我一直想要解决的问题。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: