windows 如何为 C++ 开发配置 Vim?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1957480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to configure Vim for C++ development?
提问by Anonymous
I'm learning C++ using Vim as an editor on Windows XP, however I found a issue that I have listed below.
我在 Windows XP 上使用 Vim 作为编辑器学习 C++,但是我发现了下面列出的问题。
- I have downloaded and installed c.vim and it is a essential file, however when I start vim it shows the message
C/C++ template file 'C:\Program Files\Vim\vimfiles\c-support/templates/Templates' does not exist or is not readable
, How do i fix this problem? - How would i make vim compile a C++ STL file?
- 我已经下载并安装了 c.vim,它是一个必不可少的文件,但是当我启动 vim 时,它显示消息
C/C++ template file 'C:\Program Files\Vim\vimfiles\c-support/templates/Templates' does not exist or is not readable
,我该如何解决这个问题? - 我如何让 vim 编译 C++ STL 文件?
回答by Tamás Szelei
For your first problem: I suspect that you didn't extract all the files in the archive (that c.vim came in). The c.vim documentation (README.csupport) says:
对于你的第一个问题:我怀疑你没有提取存档中的所有文件(那个 c.vim 进来了)。c.vim 文档 (README.csupport) 说:
The subdirectories in the zip archive cvim.zip mirror the directory structure which is needed below the local installation directory $HOME/.vim/ for LINUX/UNIX ($VIM/vimfiles/ for Windows)
zip 压缩包 cvim.zip 中的子目录反映了本地安装目录 $HOME/.vim/ for LINUX/UNIX ($VIM/vimfiles/ for Windows) 下所需的目录结构
This means that you need to uncompress the entire archive as it is into your vimfiles directory.
这意味着您需要将整个存档解压缩到您的 vimfiles 目录中。
There are some other steps to follow, detailed in the documentation.
还有一些其他步骤需要遵循,在文档中有详细说明。
As for your second issue: you need a Makefile to do that. If you have never done this before, I suggest using cmaketo generate a Makefile. You will also need GNU tools for Windows; Cygwinor MinGWare the most popular choices. I haven't use them, it is easier to do all this on some *nix OS :).
至于你的第二个问题:你需要一个 Makefile 来做到这一点。如果您以前从未这样做过,我建议您使用cmake生成一个 Makefile。您还需要适用于 Windows 的 GNU 工具;Cygwin或MinGW是最受欢迎的选择。我没有使用它们,在某些 *nix 操作系统上更容易完成所有这些操作:)。
When done, use :cd
(if you are not in your working directory), and :make
. Use :cl
to list the compiler output, :cn
to jump to the next error. There are some other useful commands for compiling. You might find these resources useful:
完成后,使用:cd
(如果您不在工作目录中)和:make
. 使用:cl
列出的编译器输出,:cn
跳转到下一个错误。还有一些其他有用的编译命令。您可能会发现这些资源很有用:
Also, I found the Nerd Commentera very useful companion.
此外,我发现书呆子评论者是一个非常有用的伴侣。
I found that Vim acts somewhat like alien on Windows; it is designed for an *nix-like operating system. I think it is possible to craft a similar environment for it, and use it mostly successfully, but it is so much easier to do on some linux, as it is "instantly home" there.
我发现 Vim 在 Windows 上的表现有点像外星人;它是为类似 *nix 的操作系统设计的。我认为可以为它制作一个类似的环境,并且大部分情况下都可以成功地使用它,但是在某些 linux 上这样做要容易得多,因为它在那里“立即回家”。
Anyway, if you wish to stick with Windows, I think you can find a way to accomplish what you want. Good luck.
无论如何,如果你想坚持使用 Windows,我认为你可以找到一种方法来完成你想要的。祝你好运。
回答by Ekk
- Download Vimand install to your computer.
- Download c.vimand extract to
$Vim\vimfiles\
- Download MinGWand install to your computer, make sure that you check
C++ Compiler
at Select Components. - Add
C:\MinGW
to system Path variable - Edit _vimrc file, add set
makeprg=mingw32-make
after linebehave mswin
- Test your Vim with hello world, use
!g++ c:\full_path\filename.cpp -o c:\full_path\output.exe
.