11 votes
Accepted

How do I align C++ comments to be compliant with Google styling?

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 ...
FDinoff's user avatar
  • 2,006
10 votes

Quick search, limited to a C++ function

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 ...
DJMcMayhem's user avatar
  • 17.5k
10 votes

Competitive Programming Vimrc is too long

set nocp is not actually needed if your vimrc is located at ~/.vimrc or ~/.vim/vimrc. Many of your commands can be abbreviated even further sy on colo torte se rnu nu nowrap hi=1000 cb=unnamed si ts=...
Mass's user avatar
  • 14k
10 votes

How can I compile cpp using Vim?

(I've answered this question so many times that I've lost the count, and impossible to find a complete answer in the lot... I'll bookmark this answer this time...) Everything starts with Vim quickfix ...
Luc Hermitte's user avatar
  • 17.3k
9 votes

Why doesn't YouCompleteMe complete function paramters?

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,...
hippunk's user avatar
  • 301
9 votes

How to get intelligent C++ auto-completion?

One option (what I currently use) I don't use YouCompleteMe anymore. coc-clangd is much better and simpler. Today I use coc.nvim + coc-clangd instead. Another option (what I used to use) YouCompleteMe ...
oblitum's user avatar
  • 276
8 votes

Quick search, limited to a C++ function

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 ...
Luc Hermitte's user avatar
  • 17.3k
8 votes

Jumping to start/end of function definition in C++

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 ...
Luc Hermitte's user avatar
  • 17.3k
7 votes

How do I add skeleton text to new vim files?

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 ...
electriccello's user avatar
7 votes
Accepted

Competitive Programming Vimrc is too long

The first line really should be runtime defaults.vim. This is a standard file and it must be present in all Vim installations. Among other things, it saves from typing syntax on filetype plugin indent ...
Matt's user avatar
  • 20.6k
6 votes
Accepted

How to disable YouCompleteMe's error checking?

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 ...
muru's user avatar
  • 24.8k
6 votes
Accepted

Plugin to display a smarter method tag list

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 ...
Luc Hermitte's user avatar
  • 17.3k
5 votes

How do I add skeleton text to new vim files?

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. ...
Luc Hermitte's user avatar
  • 17.3k
4 votes
Accepted

Is it possible to get the rule (cinoptions) that govern the indentation for a specific line in vim

" 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) ...
dedowsdi's user avatar
  • 6,238
4 votes

Vim, ctags and overloading

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 ...
romainl's user avatar
  • 40k
4 votes

Vim syntax highlighting of numeric literals with single-quote digit separators

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\+...
Martin Tournoij's user avatar
4 votes

Jumping to start/end of function definition in C++

I'm not aware of anything direct and foolproof. It may very well exist in a plugin somewhere, of course. ][ will take you to the next closing curly brace in column one. If your code is properly ...
Dan J.'s user avatar
  • 206
4 votes

Compiling and running multiple c++ files from vim

: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 ...
Rich's user avatar
  • 31.7k
4 votes

Quick search, limited to a C++ function

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 ...
romainl's user avatar
  • 40k
4 votes
Accepted

Remove colon from keyword in C++ file?

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. ...
Wolfie's user avatar
  • 667
4 votes

How to change Operator highlight color in Vim?

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 ...
Luc Hermitte's user avatar
  • 17.3k
4 votes
Accepted

Understanding indenting rules for C++ files

Indentation of C++ (and also C, Objective-C and even Java) is typically handled by enabling the 'cindent' option, which uses Vim's built-in C-indenting implementation, which recognizes elements of ...
filbranden's user avatar
  • 28.7k
4 votes

Competitive Programming Vimrc is too long

There are a few interresting things already in the default C and C++ filetype plugins -> filetype plugin indent on. This should enable smart indenting. No need anymore to use tabs, which could be ...
Luc Hermitte's user avatar
  • 17.3k
4 votes
Accepted

Don't auto-extend c/c++ trailing comments

Add / to formatoptions set formatoptions+=/ as described in :h fo-table: *fo-o* o Automatically insert the current comment leader after hitting 'o' or 'O' in Normal ...
Maxim Kim's user avatar
  • 13.1k
3 votes

How can I highlight WinAPI functions in C++?

You've already found how to highlight these types from the link you've posted in your question; by adding these lines to after/syntax/c/winapi.vim (see How can I add additional syntax highlighting ...
Martin Tournoij's user avatar
3 votes

Quick search, limited to a C++ function

An imperfect solution is using folds. Fold everything: set foldmethod=syntax set foldlevel=0 set foldminlines=0 Tell Vim not to open folded areas for search results: set foldopen-=search And then ...
muru's user avatar
  • 24.8k
3 votes

Quick search, limited to a C++ function

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 ...
VanLaser's user avatar
  • 9,680
3 votes
Accepted

Rearrange c++ const and reference specifiers

Just escape the & with a backslash. %s/const \(.\{-}\) &/\1 const \& The & in the replace part inserts the entire matched pattern. See :help s/\&.
Ralf's user avatar
  • 9,157
3 votes
Accepted

Autocompletion plugin for c/c++ with specific header path?

TL;DR: Set 'path' to include the path to your include files. In your example: set path+=/path Native completion from include files Vim native completion is quite useful for C and C++ files, Vim can ...
filbranden's user avatar
  • 28.7k
3 votes
Accepted

How to change in gvim GTK file browser the default file mask wildcard (glob)?

The browsefilter variable is a convenient way to add custom glob like filters for the graphical :browse dialog and select only the relevant filetypes for display. As you discovered, those are usually ...
Christian Brabandt's user avatar

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