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 ...
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 ...
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=...
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,...
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 ...
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 ...
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 ...
8
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 ...
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 ...
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 ...
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 ...
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 ...
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. ...
5
votes
Search and replace, but ignore text in quotes
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))/...
5
votes
Using the % command in c++
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,...
5
votes
Accepted
Navigation with Tagbar
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 ...
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 ...
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\+...
4
votes
syntastic C++14 support
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:...
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)
...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
filetype-c++ × 75vimrc × 14
filetype-c × 14
neovim × 9
syntax-highlighting × 8
indentation × 8
ctags × 6
autocompletion × 5
tags × 5
key-bindings × 4
autocmd × 3
folding × 3
plugin-you-complete-me × 3
comments × 3
plugin-ale × 3
ide × 3
plugin-syntastic × 3
plugin-clang-complete × 3
vimscript × 2
substitute × 2
colorscheme × 2
formatting × 2
quickfix × 2
plugin-coc × 2
makeprg × 2