Configuring Vim for C++

C++VimConfiguration

C++ Problem Overview


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

  • 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.

May be you could provide some configs (with explanations), or links to tutorials, plugins I could make use of?

C++ Solutions


Solution 1 - C++

Edit: Updated as of July 2013

Solution 2 - C++

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

  • 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

Solution 3 - C++

NERDTree http://www.vim.org/scripts/script.php?script_id=1658

Exuberant ctags (vim already supports the hotkeys natively) http://ctags.sourceforge.net/

taglist: http://vim-taglist.sourceforge.net/

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDraco AterView Question on Stackoverflow
Solution 1 - C++Thanh DKView Answer on Stackoverflow
Solution 2 - C++icecrimeView Answer on Stackoverflow
Solution 3 - C++ThePoseyView Answer on Stackoverflow