Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Vim for C++

People also ask

Is vim good for C development?

It uses clang to generate a list of suggestions and works fine for both C and C++. To let clang know about your include directories custom defines, you should place your -I and -D compiler flags into the .

What does vim do in C?

c (change) takes a vi/vim motion (such as w , j , b , etc.). It deletes the characters from the current cursor position up to the end of the movement. Note that this means that s is equivalent to cl (vim documentation itself claims these are synonyms). r (replace) never enters insert mode at all.


  • Code complete: Omni completion or Clang autocomplete or YouCompleteMe
  • Real time syntax checking: Syntastic
  • Switching between source and header file: A plugin
  • Snippets: Snipmate or UltiSnip
  • Search for reference of variables, functions, classes, etc.: Cscope
  • Go to definition: Ctags or part of YouCompleteMe subcommands mentioned above
  • Refactoring tools: Refactor, lh-refactor
  • Useful text objects: Arg text object and Class text object
  • C++ category in Vim Tips wiki
  • Luc Hermitte's C/C++ plugin
  • Not C++ specific but I also recommend either FuzzyFinder or Command-T or Unite for 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: Taglist or Tagbar

Edit: Updated as of July 2013


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

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.