为 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:55:01  来源:igfitidea点击:

Configuring Vim for C++

c++vimconfiguration

提问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

Edit: Updated as of July 2013

编辑:截至 2013 年 7 月更新

回答by icecrime

I'm using vimas my C++ editor, however I'm not using many 'exotic' stuff.

我正在vim用作我的 C++ 编辑器,但是我没有使用很多“异国情调”的东西。

  • Regarding completion, I'm using the non-contextual ^Pand ^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 .ccto .hswitching, 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 东西,但有很多资源可以谷歌搜索。