As of May 31, 2023, we have updated our Code of Conduct.
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. ...
PragmaticProgrammer's user avatar
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 ...
hgiesel's user avatar
  • 1,894
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 (....
dedowsdi's user avatar
  • 6,058
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 ...
garyjohn's user avatar
  • 6,174
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 ...
doraemon's user avatar
  • 1,597
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 ...
Martin Tournoij's user avatar
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 ...
Pavan's user avatar
  • 141
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 :...
cassepipe's user avatar
  • 329
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

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 ...
Luc Hermitte's user avatar
  • 16.7k
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 ...
Martin Tournoij's user avatar
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
Christian Brabandt's user avatar
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, ...
statox's user avatar
  • 48.5k
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 '...
Ralf's user avatar
  • 8,957
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 ...
salchint's user avatar
  • 196
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, ...
Dmitry's user avatar
  • 396
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 ...
MaNyYaCk's user avatar
  • 175
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: ...
filbranden's user avatar
  • 27.5k
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-...
user938271's user avatar
  • 5,747
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 ...
Petr Skocik's user avatar
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....
Luc Hermitte's user avatar
  • 16.7k
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 ...
filbranden's user avatar
  • 27.5k
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 ...
Matt's user avatar
  • 19.5k
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 ...
Luc Hermitte's user avatar
  • 16.7k
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 ...
Your move creep's user avatar
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 ...
Luc Hermitte's user avatar
  • 16.7k
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'...
Luc Hermitte's user avatar
  • 16.7k
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
Lucas's user avatar
  • 1,579
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++.
Johann Gerell's user avatar
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.
Luc Hermitte's user avatar
  • 16.7k

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