30

I really like clang_complete for this. It does require clang, and you need to tell it where libclang resides in your system. After that, it works wonderfully. People might suggest YouCompleteMe, but to be honest, that plugin is hugely bloated for what it says it does, and it requires way too many steps to install. I also had it segfault Vim on multiple ...


18

Exuberant ctags is the simplest way to achieve this. Under GNU/Linux (e.g. Ubuntu or Debian) you should be able to just do sudo apt-get install exuberant-ctags (For OSX "$ brew install ctags" should suffice; for Windows you might want to visit http://ctags.sourceforge.net/ and download the standalone executable) Then navigate to your project's root ...


11

clang-format is a command line tool that formats c++ code. One of the default formatters is google. clang-format -style=google There are plugins that would allow you to run clang-format in vim. One such plugin is https://github.com/rhysd/vim-clang-format (I have not used it, it was the first I found)


9

Here's how I would do it. Add this to your .vimrc vnoremap if [[O][ Explanation: vnoremap means map the left hand side if to the right hand side [[mO][ while you're in visual mode. if means In Function, although you can rename this if you like. [[ jumps to the beginning of the function. O moves to the other end of your visually selected text, and then ][ ...


8

Finally found it! Completing parameters is not a part of the YCM behaviour. See this YCM issue. There's an old fork from oblitum which could grant this feature. That's what misled me. Unfortunately, this part of the fork seems unmaintained and after a few tries I couldn't make it work. So, I tried out clang_completer which has the parameter completion ...


8

YouCompleteMe (Link) plugin has been work great for me. It uses libclang to generate the autocomplete feature, providing accurate completion. It has a lot of customization, specially when working with compilation flags. You can edit the "flag generator" editing a python script per project (Example). But, to me the main advantage is that it supports Clang ...


7

As we cannot expect C++ code to have their function-scope brackets on the first column, we cannot rely on the default behaviour of ]] and ][. A few weeks ago I've added this feature into lh-cpp. I won't describe here how it works as I've done it in answer to another similar question on vi.SE: Quick search, limited to a C++ function (the idea is that I rely ...


6

DJ McMayhem's solution inspired me to write my own that relies on ctags and on matchit to do a proper analysis of function boundaries. The difficult part has been already done by lh-dev and lh-tags for several years: the current file is parsed through ctags with the right options we look for all function definitions in the tags database which is restricted ...


6

Skeleton text from an existing file can be added to a new file by inserting the line autocmd BufNewFile *.cpp r C:\(full file path of skeleton text file) into the vimrc. The BufNewFile event does not work if the new file is created in two steps using :enew then :sav filename. Instead, creating a new file using :e filename triggers the BufNewFile event's ...


6

I cannot provide an answer different to the one I gave in other similar questions. While tag-based plugins may present a complete list of existing overloads in a way much more ergonomic than :tselect (they may even provide a filter option like my lh-tags plugin), they cannot help restrict the list of overloads to the one matching the types of the objects ...


5

Indeed, template expander plugins will help you in this task. :read is the step 0 of template expander plugins. For instance, mu-template will try to include foo.h from foo.cpp if foo.h is detected. It'll also permit to expand headers with dynamic data within them (date, author, license/copyright, etc).


5

The g:ycm_show_diagnostics_ui variable controls this: The *g:ycm_show_diagnostics_ui* option When set, this option turns on YCM's diagnostic display features. See the _Diagnostic display_ section in the _User Manual_ for more details. So, do: let g:ycm_show_diagnostics_ui = 0


5

It can be done by testing the syntax name behind the variable to replace: :%s/variable/\=(match(map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")'), '\cstring')==-1 ? 'NEw' : submatch(0))/g But nobody will want to use that. Instead, we'd better define a new command. :command! -bang -nargs=1 -range SubstituteUnlesString \ <line1>,<...


5

You can force a motion to be linewise; then, the % would include the full last line, including the trailing ;, for example yV%. Unfortunately, if you use the matchit plugin, that doesn't work any more, but you can instead use visual mode: V%y (interestingly, this is the reverse of the above!) Alternatively, you could define a custom motion for that.


4

" tell which cinoption take effect for current line com! WhichCinoption call s:which_cinoption() function s:which_cinoption() abort " test if cindent take effect if !empty(&indentexpr) echo "'indentexpr' exists, it overrides 'cindent'." return endif if !&cindent echo "'cindent' is currently disabled." return endif " ...


4

A variety of methods are at your disposal There are some very useful commands listed here, most notably [I, which will display all lines in the current and all included files containing the keyword under the cursor. See :h [I and :h include-search. You can :grep or :vimgrep to search for occurrences of a particular symbol (or any pattern for that matter), ...


4

So far I can name two solutions to the problem of finding either the declaration or the definition of a function. I know there is another well know tags based solution, but as I don't use it, I'll let others give it to you. The more trendy one first: YouCompleteMe has a :GoToDefinition and a :GoToDeclaration pair of commands. The one I use (it's hard to ...


4

Finding the beginning and end of a function can be difficult, especially in a language without a function keyword… and many conflicting indent styles. If your function ends with a closing brace alone on its own line (as in 10 out of the 13 styles listed here), you could visually select it with something like this: xnoremap if /^\s*}<CR><Esc>V% ...


4

The documentation (:help ctrl-]) says: When there are several matching tags for {ident}, jump to the [count] one. When no [count] is given the first one is jumped to. g] may not be what you are looking for but that's the best you can get in Vim. Basically, you can't expect ctags and Vim to understand your code, so you'll have to look for a smarter ...


4

The vim-jp/vim-cpp repo included this change in July 2016: syn match cNumber display contained "\d\('\=\d\+\)*\(u\=l\{0,2}\|ll\=u\)\>" syn match cNumber display contained "0x\x\('\=\x\+\)*\(u\=l\{0,2}\|ll\=u\)\>" syn match cNumber display contained "0b[01]\('\=[01]\+\)*\(u\=l\{0,2}\|ll\=u\)\>" If you don't want to use this repo, ...


4

You could put setlocal iskeyword-=: inside ~/.vim/after/ftplugin/cpp.vim Loads automatically when you open files where the filetype is cpp. If it doesn't work, try setting filetype plugin on. Update: Or you could do autocmd FileType cpp :setlocal iskeyword-=: In your .vimrc, but I recommend you put it in a ftplugin - it keeps your .vimrc clutter-free.


4

:make doesn't have to actually use a Makefile. Try something like: :let &makeprg = "g++ *.cpp -o [Filename]" You can then run the command with :make and if desired you can set up a normal mode mapping for this with something like: :nnoremap <leader>m :make<CR> See :help 'makeprg' for more details. You'll probably also want to ensure '...


4

It indeed looks like cppOperator links to Operator which links to Statement (-> :hi cppOperator), but I've never seen these operators displayed differently... It's just for the keywords. See syn list cppOperator. I guess you'd have to add these symbols to the cppOperator list. You may need a syn match that takes care of not overlapping with cFloat and some ...


3

In my .vimrc, I have: let g:syntastic_cpp_checkers = ['gcc'] let g:syntastic_cpp_compiler = 'gcc' let g:syntastic_cpp_compiler_options = '-std=c++14' And, if you have YCM enabled: let g:ycm_show_diagnostics_ui = 0 And now it works!


3

There are few alternatives. The first one is ctags. If you need a more advanced indexer then cscope is a better alternative. For instance it will allow you to list all callers of given function. These tools will index your code without really understanding it properly (they do have a simple grammar definition to know what given symbol means). It's also ...


3

The :GOTOIMPL command from lh-cpp is able to jump to a function definition from its declaration, or to provide a default empty definition in the case none was found. Some features I can think of: The command already understands comments, exception specifications, keywords that shall not be copied (but possibly copied within comments)(virtual, static, ...)....


3

Whew, this one was fun! :g/.*\n^{/yank A<cr>:bn<cr>pkdd:%s/$/;/<cr>:g/::/d B<cr>A<cr><cr>class <cr>{<cr>};<esc>"BP:%s/[^ ]\+:://<cr>j%jyt(kk$p=ipjA<cr>public:<esc> You can go ahead and map that to a single keystroke in your .vimrc: nnoremap <C-b> :g/.*\n^{/yank A<cr>:bn<...


3

YouCompleteMe isn't that hard to install, and it has been quite stable for me, I've migrated from clang_complete to YouCompleteMe years ago. One thing I agree, it's indeed bloated with a huge commit history, many internal dependencies and support for many languages you may not care for but still will end up cloning its associated submodules. That, that's an ...


3

Another way: use ctags etc. to find the target function, go there move cursor forward inside the function body use Osyo Manga's search operator (depends on vim-operator-user) to only search inside the current block. E.g.: " configure the plugin (once, vimrc): map g/ <Plug>(operator-search) " 1. use ctags etc. to jump to the beginning of the target ...


Only top voted, non community-wiki answers of a minimum length are eligible