16
votes
How to clang-format the current buffer on save?
You can add the following to your .vimrc
1. function FormatBuffer()
2. if &modified && !empty(findfile('.clang-format', expand('%:p:h') . ';'))
3. let cursor_pos = getpos('.')
4. ...
7
votes
Accepted
Jumping from function definition tag to prototype tag
Okay I've done it:
It all has to do with ctags:
First create two files called foo.c and foo.h to test it:
In foo.h write down:
int bar(void);
In foo.c write down:
int bar(void) { /* */ }
And in ...
6
votes
Accepted
Is it possible to create a snippet to "expand" struct members to fill?
readtags
universal-ctags provide readtags to filter tags:
Read all members of a struct:
readtags -Q '(and (eq? $kind "member") (eq? $scope-name "struct_name") )' -l
(and (...) (...)): (...) and (....
6
votes
Accepted
Auto Indent (the = key) of C switch block
The configuration of C indenting in Vim is controlled by the cinoptions option. That particular aspect of indenting is controlled by the l (lower-case L) flag. When set to any value other than 1, it ...
5
votes
How do you navigate large source files with VIM?
I think what you are looking for is a plugin like tagbar, which can create a sidebar to display all the functions, struct/class, macros, etc. It also allow you to click (or press enter on) the tag and ...
4
votes
Vim syntax highlighting for custom C types
The way built-in types are declared is very simple. From /usr/share/vim/vim74/syntax/c.vim:
syn keyword cType int long short char void
syn keyword cType signed unsigned ...
4
votes
How do you navigate large source files with VIM?
You can enable code folding using the vim option:
set foldmethod=syntax
This reduces the amount of code you see at once and makes it manageable.
After enabling code folding, use below commands for ...
3
votes
Iterate through functions calls in various files
It seems that :grep some_word is what I was looking for. It populates a quickfix list that you can navigate with :cnext and :cprev.
A good idea is to map those to ]q and [q respectively.
:cfirst and :...
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 ...
3
votes
How do I highlight pc-lint comments in C/C++
Did you have a look at syntax/doxygen.vim? This is where doxygen highlighting is defined.
What you need to do then, is to add a file for pclint in ~/.vim/syntax/, and a syntax rule inspired from the ...
3
votes
Add a Semicolon Automatically in C With a Vim Plugin
Languages with automatic semicolon insertion such as JavaScript and Go have as bunch of edge-cases where they do unexpected things, and any C solution will probably be no different. In C macros in ...
2
votes
Color change in the middle of #define
That looks like issue 281 and should be fixed with newer versions of Vim 7.4
2
votes
Customize vim to automatically check function name against its prototype
I think you might solve your problem with the Omni Completion function working with a program like exuberant ctags.
The idea is to generate a tags file containing the different classes, constants, ...
2
votes
Accepted
Indenting a c file adds spaces before function's type?
Open a C file and have a look at cinoptions
set cinoptions?
Most likely this is empty. Now add t0.
set cinoptions+=t0
Reformat your C code, and the type should not be indented anymore.
See :help '...
2
votes
How do you navigate large source files with VIM?
Tagbar can help to navigate through a large number of functions in one single file. Among other features, it supports sorting by name or line number, which I find very helpful.
marks can also be a ...
2
votes
How do you navigate large source files with VIM?
In addition to ctags-based plugins like Taglist i use cscope. Some plugins may be useful: like cscope_macros and CCTree. Before using ctags or cscope you have to make tags file and cscope database, ...
2
votes
How do you navigate large source files with VIM?
Something that I am doing is using
Plugin Gutentags : Used for creating tags across the project from root folder.
Plugin Tagbar : Used for navigating within the files.
Plugin Ack : Used to ...
2
votes
Accepted
manually set syntax highlighting works from command-line mode but not from .vimrc/init.vim
The files in the syntax directory should be named after the filetype detected by Vim. In the case of your C++ code, I'd expect it would detect it as cpp. You can check that with the following command:
...
2
votes
How does ft-c-omni work and how can I make it faster?
So how is that feature implemented and is there an undocumented way of
making it go faster (pre-computing, caching, ...) so that it can be usable
in large projects such as the Kernel? Or is ft-...
2
votes
Accepted
Preventing the colon from causing indentation to be deleted
My vanilla vim setup (empty .vimrc) had the cindent option on an the related
cinkeys option set to (the default) cinkeys=0{,0},0),:,0#,!^F,o,O,e.
Removing the : from the list disables the reindenting ...
2
votes
Edit compile and run cycle
At this moment detecting whether the compilation has successfully ended to chain with something else requires scripting.
For more detailed explanations/example, see this SO Q/A: https://stackoverflow....
1
vote
Accepted
How do I make Clang Completer Auto-Complete/Auto Show options
Check out the asyncomplete plug-in. It will automatically show the autocomplete popup menu as you start typing.
This plug-in only provides the base for completion and depends on add-ons to implement ...
1
vote
Accepted
How to tell vim to ignore extern "C" brakets while indenting?
setlocal cinoptions=E-s
See :h cinoptions-values.
Also make sure that :h 'equalprg' is set to empty, so the internal Vim formatter is used. If not, see man pages of an external formatter tool ...
1
vote
Is it possible to create a snippet to "expand" struct members to fill?
At this time, I have something extremely similar in my lh-cpp plugin for C++. Within a class context, I type :Constructor init, and my plugin will fetch all the member data (thanks to the API of two ...
1
vote
Accepted
ALE + clangtidy + large file = big delay when linting
Since I ran this linter as an external command and it gave me the same delay to go through the file, I assume it is just really slow. So that's a shame...
P.S If you got any solutions on how to fight ...
1
vote
Accepted
Insert C/C++ loops and statements templates automatically
There exist many ways to define snippets for control statements: via abbreviations or via snippets. I remember a Q/A about abbreviations versus snippet plugins.
TL;DR: We can achieve the same things ...
1
vote
Accepted
Is there a way to open header file in c?
We need more details.
Header files aren't supposed to contain function definitions, in C. Function declaration, yes, but definitions, unless they are inlined, no. Could it be related to YCM? YCM isn'...
1
vote
Is there a way to open header file in c?
There is a dedicated plugin for switching to header files:
https://www.vim.org/scripts/script.php?script_id=31
1
vote
Accepted
Folding doesn't work for C/C++
After some detective work I tracked down the cause of my issue being that I had a .vim file in my plugin directory that redefined OperatorChars, which broke the syntax based folding for C and C++.
1
vote
folding, curly bracket under the function name
I did define VimFold4C that tries its best to fold C & C++ codes. The caveat is when we are modifying the code: I'm using caches in order to speed up the fold processing, but alas it has quirks.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
filetype-c × 43filetype-c++ × 14
syntax-highlighting × 13
indentation × 9
vimrc × 5
neovim × 3
ide × 3
vimscript × 2
folding × 2
formatting × 2
comments × 2
tags × 2
snippets × 2
key-bindings × 1
search × 1
autocompletion × 1
microsoft-windows × 1
save × 1
ctags × 1
plugin-coc × 1
original-vim × 1
plugin-ale × 1
makeprg × 1
plugin × 1
ins-completion × 1