Skip to main content
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.7k
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
  • 14.2k
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.5k
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

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.5k
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.5k
7 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.5k
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.9k
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
  • 25k
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
  • 41.2k
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
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,298
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
  • 41.2k
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

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
  • 32.2k
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.5k
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
  • 29k
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.5k
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.6k
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
  • 25k
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,770
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,287
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
  • 29k
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
3 votes

Working with large Visual Studio oriented codebase

Not really the answer you are looking for but I thought I'd share it in case anyone finds it useful. Whenever I have to use Visual Studio, the first thing I do is to register gVim as an external tool. ...
Friedrich's user avatar
  • 2,269
3 votes

Any C/C++ definition generators for Vim?

Here is a vimscript function that creates a definition based on the current line declaration: function! CreateDefinition() abort let state=winsaveview() yank normal! [{?class\s\+\zs\h\+"...
Vivian De Smedt's user avatar
2 votes

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

@dedoswdi's answer was extremely helpful! I adapted it somewhat to produce the result for each line on the buffer. My adapted script can be found in this Gist. After applying it to the original C++ ...
filbranden's user avatar
  • 29k

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