10/25/2019 Configuring Vim for C++ - Stack Overflow
Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen
now
Configuring Vim for C++
Asked 8 years, 11 months ago Active 8 months ago Viewed 64k times
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
105 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.
130 May be you could provide some configs (with explanations), or links to tutorials, plugins I could
make use of?
c++ vim configuration
edited Feb 20 at 10:46 asked Nov 21 '10 at 12:30
sandris Draco Ater
965 7 24 17.2k 7 54 83
4 +1 for the sheer masochism of wanting to use vim as your IDE :) vim has its uses (especially for editing files
remotely in my experience), but anyone who actually wants to use it for code editing has chutzpah in my view.
– Stuart Golodetz Nov 21 '10 at 15:35
34 @sgolodetz: Then there are quite a lot of people with chutzpah out there. – Cascabel Nov 21 '10 at 16:35
1 @Jefromi: Yup I do realise that :) It has always seemed like masochism to me though...in a sort of slightly
admirable way. – Stuart Golodetz Nov 21 '10 at 16:40
1 @sgolodetz troll, much? – wilhelmtell Nov 21 '10 at 21:27
4 In retrospect, I guess posting the equivalent of "I'm a bit dubious about vim" on a post likely to be frequented
by a lot of vim enthusiasts might have been a little provocative -- it was meant to be a tongue-in-cheek
comment rather than the start of an argument though. – Stuart Golodetz Nov 21 '10 at 21:44
3 Answers
Code complete: Omni completion or Clang autocomplete or YouCompleteMe
Real time syntax checking: Syntastic
131 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
https://stackoverflow.com/questions/4237817/configuring-vim-for-c 1/3
10/25/2019 Configuring Vim for C++ - Stack Overflow
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
edited Mar 16 '15 at 17:22 answered Nov 21 '10 at 16:23
Luc Hermitte Thanh DK
26.7k 5 54 70 2,812 3 19 18
I've fixed the link to my C&C++ ftplugins suite. Thanks for the "advertizing" :) – Luc Hermitte Nov 21 '10 at
21:25
Also I may recomend FSwitch plugin instead of A plugin. – W55tKQbuRu28Q4xv Feb 26 '13 at 4:13
1 Luc's lhCpp is incompatible with vundle (I think due to svn repo) and no install process I like personally -
recommend checking out github.com/Raimondi/delimitMate – netpoetica Sep 15 '13 at 14:28
2 +1 a very complete (and up to date) answer deserves it, it's nice to see some of the more reclusive members
posting these great answers. How thorough your answer is, is quite helpful, while at the same time not
overwhelming, even to a new vim user. – osirisgothra Jul 21 '14 at 10:58
1 How about vim-rtags? It's good for c++ code navigation, has a rename functionality. – P4C Jul 28 '16 at 9:57
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 .
8
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
https://stackoverflow.com/questions/4237817/configuring-vim-for-c 2/3
10/25/2019 Configuring Vim for C++ - Stack Overflow
answered Nov 21 '10 at 12:46
icecrime
58k 9 87 105
Nice function. I was looking for something like that.... – Jepessen May 11 '17 at 9:59
NERDTree http://www.vim.org/scripts/script.php?script_id=1658
Exuberant ctags (vim already supports the hotkeys natively) http://ctags.sourceforge.net/
2
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.
answered Nov 21 '10 at 14:17
ThePosey
2,409 2 15 18
https://stackoverflow.com/questions/4237817/configuring-vim-for-c 3/3