Skip to main content
Share Your Experience: Take the 2024 Developer Survey
17 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,944
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,268
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,667
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
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.5k
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
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
  • 395
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
  • 17.4k
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
  • 9,257
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
  • 206
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
  • 416
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

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,987
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
  • 29k
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
  • 17.4k
2 votes

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

When cindent is on, the comment formatting options are somehow overridden by the cindent and formatoptions settings. :help format-comments Enabling 'cindent' will override the alignment flags in many ...
Vivian De Smedt's user avatar
1 vote

Edit compile and run cycle

You can just add running the program to the Makefile as a target: for example, one named run. Then you just :make run. run has a dependency on the program, to make sure that the program is created or ...
Kaz's user avatar
  • 481
1 vote
Accepted

Edit compile and run cycle

Assuming you have the makeprg set up correctly: let &l:makeprg = 'cd build && make' The &l: syntax for let sets local variables; you can also use setlocal but then you need to use ...
Martin Tournoij's user avatar
1 vote

Problem with coc-clangd

tl;dr: You need to tell clangd how your project is built and where to find (non-standard) libraries, source files and headers etc., by generating compile_commands.json or similar. When using language ...
frippe's user avatar
  • 168
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
  • 29k
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
  • 20.8k
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
  • 17.4k
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

Vim and enhanced commentify weird behavior for C

I cannot answer directly your answer, cannot add a comment, but I'll still answer. It seems like EnhancedCommentify have not beed updated for 6 years now. I suggest you try another plugin. I ...
perelo's user avatar
  • 461
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
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
  • 17.4k

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