为 C++ 配置 Vim
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4237817/
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
Configuring Vim for C++
提问by Draco Ater
I would like to make vim my C++ editor. I have very little experience working with it and need help in configuring vim to work with C++. I need such features as
我想让 vim 成为我的 C++ 编辑器。我几乎没有使用它的经验,需要帮助来配置 vim 以使用 C++。我需要这样的功能
- code-complete (for stl and for my classes)
- switching between .cc and .h files
- may be some more tricks you, C++ and vim gurus, have.
- 代码完整(适用于 stl 和我的课程)
- 在 .cc 和 .h 文件之间切换
- 你,C++ 和 vim 大师,可能还有更多的技巧。
May be you could provide some configs (with explanations), or links to tutorials, plugins I could make use of?
可能您可以提供一些配置(带有解释),或者我可以使用的教程、插件的链接?
回答by Thanh DK
- Code complete: Omni completionor Clang autocompleteor YouCompleteMe
- Real time syntax checking: Syntastic
- Switching between source and header file: A plugin
- Snippets: Snipmateor UltiSnip
- Search for reference of variables, functions, classes, etc.: Cscope
- Go to definition: Ctagsor part of YouCompleteMe subcommandsmentioned above
- Refactoring tools: Refactor, lh-refactor
- Useful text objects: Arg text objectand Class text object
- C++ category in Vim Tips wiki
- Luc Hermitte's C/C++ plugin
- Not C++ specific but I also recommend either FuzzyFinderor Command-Tor Unitefor file navigation. With either of these, you don't even need tabs (which does not scale for 10+ files) to manage your project.
- Class navigation: Taglistor Tagbar
- 代码完成:Omni 完成或Clang 自动完成或YouCompleteMe
- 实时语法检查:Syntastic
- 在源文件和头文件之间切换:一个插件
- 片段:Snipmate或UltiSnip
- 搜索变量、函数、类等的引用:Cscope
- 转到定义:Ctags或上述YouCompleteMe 子命令的一部分
- 重构工具:Refactor, lh-refactor
- 有用的文本对象:Arg 文本对象和Class 文本对象
- Vim Tips wiki 中的 C++ 类别
- Luc Hermitte 的 C/C++ 插件
- 不是 C++ 特定的,但我也推荐FuzzyFinder或Command-T或Unite进行文件导航。使用这些中的任何一个,您甚至不需要选项卡(不能针对 10 多个文件进行缩放)来管理您的项目。
- 类导航: Taglist或Tagbar
Edit: Updated as of July 2013
编辑:截至 2013 年 7 月更新
回答by icecrime
I'm using vim
as my C++ editor, however I'm not using many 'exotic' stuff.
我正在vim
用作我的 C++ 编辑器,但是我没有使用很多“异国情调”的东西。
- Regarding completion, I'm using the non-contextual
^P
and^N
. I have a bunch of user defined abbreviations for my C++ use, for example :
abbreviate bptr boost::shared_ptr abbreviate cstr const std::string &
I have several functions for "code snippets" like things, for example :
function! IncludeGuard() let basename = expand("%:t:r") let includeGuard = '__' . basename . '_h__' call append(0, "#ifndef " . includeGuard) call append(1, "#define " . includeGuard) call append(line("$"), "#endif /* !" . includeGuard . " */") endfunction
The only plugin I really couldn't live without is Command-T(which requires ruby support)
- For easy
.cc
to.h
switching, you can try this plugin
- 关于完成,我使用的是非上下文
^P
和^N
. 我有一堆用户定义的缩写供我使用 C++,例如:
abbreviate bptr boost::shared_ptr abbreviate cstr const std::string &
我有几个用于“代码片段”之类的函数,例如:
function! IncludeGuard() let basename = expand("%:t:r") let includeGuard = '__' . basename . '_h__' call append(0, "#ifndef " . includeGuard) call append(1, "#define " . includeGuard) call append(line("$"), "#endif /* !" . includeGuard . " */") endfunction
我真的离不开的唯一插件是Command-T(需要 ruby 支持)
- 为了便于
.cc
对.h
开关,你可以试试这个插件
回答by ThePosey
NERDTree http://www.vim.org/scripts/script.php?script_id=1658
NERDTree http://www.vim.org/scripts/script.php?script_id=1658
Exuberant ctags (vim already supports the hotkeys natively) http://ctags.sourceforge.net/
Exuberant ctags(vim 本身已经支持热键)http://ctags.sourceforge.net/
taglist: http://vim-taglist.sourceforge.net/
标签列表:http: //vim-taglist.sourceforge.net/
snipmate: http://www.vim.org/scripts/script.php?script_id=2540
snipmate: http://www.vim.org/scripts/script.php?script_id=2540
I don't do omnicompletion just the usual ^n ^p stuff but there are plenty of resources to google for.
我不会只做通常的 ^n ^p 东西,但有很多资源可以谷歌搜索。