Skip to main content

Questions tagged [filetype-c]

Questions about the c file type.

Filter by
Sorted by
Tagged with
12 votes
2 answers
2k views

Automatically creating functions out of function prototypes from header files

Intro When programming in C and C++ you usually split your function prototypes and actual functions into a .h/.hpp and .c/.cpp file. Sadly it's very tedious to transfer the function prototypes from ...
Lukas's user avatar
  • 121
9 votes
1 answer
7k views

How to clang-format the current buffer on save?

Whats the best way to clang-format a C/C++/GLSL a buffer on save, that does nothing in the case there is no clang-format file found for a project?
ideasman42's user avatar
  • 3,763
9 votes
1 answer
3k views

Jumping from function definition tag to prototype tag

As far as I understand Vim has a built-in support for tags (ctags in this case) Now I have a common C source and C header file. The header file has void foo(void); and the source file has void foo(...
hgiesel's user avatar
  • 1,944
8 votes
1 answer
7k views

Vim syntax highlighting for custom C types

I want to use syntax highlighting for custom C types. Based on my coding convention, types can occur in the following places: typedef type1 type2; (static | extern | register | volatile)? type ...; ...
R.L's user avatar
  • 81
7 votes
5 answers
4k views

How do you navigate large source files with VIM?

First, I'm not asking about performance. I'm looking for something that will help me, mentally, get into large C source code files that I'm not yes accustomed to. Take for example readelf.c. This file ...
Evan Carroll's user avatar
  • 1,404
5 votes
2 answers
825 views

Vim `cpp` Syntax highlighter prematurely ends macros mid-word

NOTE: This question is a "manual migration" from here: https://superuser.com/q/875751/199803 My Vim syntax highlighter for ft=cpp is prematurely ending some macros mid-line. For example: (The ...
Kyle Strand's user avatar
5 votes
2 answers
83 views

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

Edit this C++ excerpt: // line 1 int xxxxxxxx = 0; // line 2 int yyyyyyyy = 0; When the cursor is in line 1 and you hit o to insert a line below it, Vim conveniently starts the new line with another /...
Camille Goudeseune's user avatar
4 votes
3 answers
790 views

Is it possible to create a snippet to "expand" struct members to fill?

In the type of c programming that I do day to day, I often have to "fill" struct members in order to pass them to an API. For example: struct measurement { double start_time; double end_time; double ...
mbl's user avatar
  • 319
4 votes
1 answer
400 views

Customize vim to automatically check function name against its prototype

I wonder if there is any method that I can use to check a function name against its prototype, which may help a lot when I make typo. For example, I once wrote a function prototype this way:void ...
Alex's user avatar
  • 1,225
4 votes
1 answer
1k views

Indenting c/c++ using lisp indentation style

I want to write c++ code in vim using lisp indentation style (closing curly braces on the same line as last statement) but I can't figure out how to configure indentation to use that style. Is there ...
jendas's user avatar
  • 41
3 votes
1 answer
640 views

Auto Indent (the = key) of C switch block

For the following switch block: If I select the switch block and apply the auto format command, the = key, I get the following: The block is formatted correctly in the first image, but it gets ...
user1135541's user avatar
  • 1,113
3 votes
1 answer
2k views

Vim to highlight functions and user-defined types

I have two scenarios where I want vim to highlight those items. Currently my fix for these are to add the return types directly into the after/syntax/c.vim file, but this gets incredibly tedious. Here ...
David542's user avatar
  • 2,455
2 votes
2 answers
598 views

Any C/C++ definition generators for Vim?

Vim is my daily driver for C++ (this would apply to C as well). As it stands, I use coc-vim with coc-clangd for code analysis. For example, when working with C++, I place my declarations in a header ...
trozzel's user avatar
  • 121
2 votes
4 answers
531 views

Edit compile and run cycle

I've just got the hang of the wonders of :make and the ability to cycle through the errors. Obviously, I have to do a set makeprg with the settings I need and everything is nice, but the problem is ...
Paul92's user avatar
  • 197
2 votes
3 answers
1k views

Color change in the middle of #define [duplicate]

Every time I have a '0' character in a #define preprocessor directive in C, I get a change of color. Neither the font nor color scheme have influence on it. It is starting to annoy me. Does anyone ...
AlBundy's user avatar
  • 21
2 votes
1 answer
589 views

How do I highlight pc-lint comments in C/C++

How do I mimic the behavior of Doxygen comment highlighting for PC-lint comments? Comments are in the following formats: /*lint ... */ //lint ... /* LINTLIBRARY */ /* ARGUSED */ /* VARARGS[N] */ <--...
thetic's user avatar
  • 21
2 votes
1 answer
244 views

How does ft-c-omni work and how can I make it faster?

As I was studying the various ways of doing completion in Vim 8.0, I came across the very interesting "omni-completion" feature and its 'omnifunc' option, which is specialized as ccomplete#...
PiCTo's user avatar
  • 369
2 votes
1 answer
176 views

Vim and enhanced commentify weird behavior for C

I am trying to use EnhancedCommentify plugin for vim and mostly using C. However I can't figure out the issue but when I comment/uncomment it uses (* ---- \*) instead of /* ----- \*/. I tried to ...
Jacques's user avatar
  • 21
2 votes
1 answer
1k views

folding, curly bracket under the function name

I have these two functions void function_one(){ return; } void function_two() { return; } when I use zM to fold the functions I get +-- 3 lines: void function_one(){-- void ...
juanpablo's user avatar
  • 121
2 votes
1 answer
274 views

Vim syntax match changes based on function type name keyword

I've written a C code syntax rule to highlight function names in function definitions as such: This is the syntax rule written in ~/.vim/syntax/c.vim: syntax match cCustomFunc /\w\+\s\+\zs\w\+(/he=e-...
user23182's user avatar
2 votes
0 answers
323 views

Tools for working with C #ifdef preprocessor directives?

I want to work with a C code with a lot of #ifdef directives. I wonder if there is a program, that will show me, which of these #ifdef's will be left in the code, and which will be cut out by ...
Peret Finctor's user avatar
1 vote
1 answer
320 views

Add a Semicolon Automatically in C With a Vim Plugin

I am a C programmer and I am looking for a plugin that automatically adds semicolons when necessary before writing changes to a file. For example, look at the following example. printf("%s\n"...
Amarakon's user avatar
  • 261
1 vote
1 answer
137 views

Iterate through functions calls in various files

I can jump to a function definition thanks to :tjump. Or I can search for a function call in a file with / but is there a way to iterate through function calls across various files ? If the solution ...
cassepipe's user avatar
  • 395
1 vote
1 answer
138 views

Indenting a c file adds spaces before function's type?

Open a c file and then type: int main and then hit: gg=G It becomes int main Is this an intended behavior? Is there a way to change this? I prefer it to be retained as is because most ...
Nishant's user avatar
  • 207
1 vote
2 answers
2k views

Is there a way to open header file in c?

I'm trying to configure vim for programming in C. I currently use YouCompleteMe and Syntastic for programming auto-completion and syntax-checking. But I came up with a problem. I cannot jump to a ...
St.Antario's user avatar
  • 1,127
1 vote
1 answer
1k views

Problem with coc-clangd

I use coc and coc-clangd for C/C++. When I want to use gtk I get this message: When I compile the file with command below, the process completes successfully. gcc `pkg-config --cflags gtk+-3.0` -o ...
Reza Hosseinzadeh's user avatar
1 vote
1 answer
118 views

How to tell vim to ignore extern "C" brakets while indenting?

I have the following in my .vimrc to indent the whole file: nnoremap cu gg=G`` I have a problem using this in source files that have #ifdef __cplusplus extern "C" { #endif // code #ifdef ...
Salahuddin Ahmed's user avatar
1 vote
1 answer
944 views

ALE + clangtidy + large file = big delay when linting

I am using ALE plugin with clangtidy linter to lint my C code and whenever I save my file and this linter gets activated it takes around 3-4 seconds for it to check for errors. File in question is ...
vimEnjoyer's user avatar
1 vote
0 answers
59 views

Syntax highlighting in parallel folders [closed]

My syntax highlighting does not work for my C-project, if I use folders in parallel. Consider this file tree: project ├── include │  ├── main.h │ ├── file1.h │ └── file2.h └── src ├── main.c ...
earthling's user avatar
  • 133
1 vote
1 answer
86 views

Loading C file overwrites indentation settings in .vimrc [duplicate]

When I open a C file in vim, it seems to think I want 8 spaces worth of indentation, even though I specify my indentation preferences in .vimrc with the below: set expandtab set softtabstop=4 set ...
Ansel Bobrow's user avatar
1 vote
0 answers
62 views

Syntax highlighting for two components of C syntax

What are the following two components that I need to target with syntax highlighting/rules? The first one is the int (or more generall, any storage class) that I want to colorize. If currently have ...
David542's user avatar
  • 2,455
1 vote
0 answers
309 views

Setting up C code highlighting

I've used vim for mostly python or web-related projects. Now I'm trying to see if I can use it to write some C code. The first thing that I've noticed is whatever setup I have, doesn't have any C code ...
David542's user avatar
  • 2,455
1 vote
0 answers
173 views

automatic popup in vim with clang_complete plugin

I want to use Vim to program in clang (*.c and *.cpp). At the moment I am trying to use the clang-complete plugin and I like the autocompletion but I have to use the <C-n> or <C-p> ...
user avatar
1 vote
0 answers
100 views

How to correctly add syntax highlighting to all c typedef [duplicate]

I saw that it's possible to manually add types to highlight, according to this post: https://stackoverflow.com/questions/20149478/how-can-i-teach-vim-about-additional-c-language-types-for-syntax-...
mbl's user avatar
  • 319
1 vote
1 answer
359 views

Using NerdCommenter to comment/uncomment blocks with old-style C comments

I'm using the NerdCommenters leader c<space> to toggle comments on blocks of C code, but when those blocks already contain C comments, they get replaced, by default with [> and <], and ...
Petr Skocik's user avatar
1 vote
0 answers
222 views

Why does cindent align statements to closing } in switch case?

I prefer this indentation style for switch cases with local variables: switch (expr) { case CONST_BLAH1: { int decl; // scope local to this case stmt; break; case CONST_BLAH2: ...
wefwefa3's user avatar
  • 1,193
0 votes
1 answer
548 views

How can I highlight WinAPI functions in C++?

How can I add syntax highlight for windows.h C/C++ apis and types? All I've found is a tiny winapi syntax file here.
scx's user avatar
  • 101
0 votes
1 answer
223 views

manually set syntax highlighting works from command-line mode but not from .vimrc/init.vim

The gruvbox colorscheme and syntax highlighting for C++ doesn't highlight some elements such as: string vector I have this: So I decided to change the colors manually using in init.vim syn keyword ...
alexzander's user avatar
0 votes
1 answer
315 views

Preventing the colon from causing indentation to be deleted

When opening a C file, then even with the vanilla setup on my Linux Mint system, if I type identifier at the beginning of an indented line and then ':' immediately after it, the indentation for that ...
Petr Skocik's user avatar
0 votes
1 answer
203 views

Can I jump to implementation in a C project with coc-clangd?

I use NeoVim with coc-clangd. I have a project in C and I use vendor library SPL for STM8S chips. SPL library is in parent directory out of my project. This is my compile_flags.txt: -xc -std=c99 -Wall ...
MarrekNožka's user avatar
0 votes
1 answer
1k views

How do I make Clang Completer Auto-Complete/Auto Show options

I have recently moved to vim and was looking into specific auto-completion plugins and tools to use for C/C++ (after YCM did not work for me). I found and installed Clang Completer and it works like a ...
programmer's user avatar
0 votes
1 answer
982 views

Folding doesn't work for C/C++

I've been having a ridiculously hard time getting C/C++ code folding to work with set foldmethod=syntax. To debug my issue I've stripped down my vimrc to only this: set foldmethod=syntax syntax on ...
Johann Gerell's user avatar
0 votes
0 answers
31 views

Indenting C with brace macros

I use a bunch of weird C macros which basically should behave like braces as far as formatting is concerned. My equalprg is empty, so I'm using vim's indenting function for = formatting. Is there any ...
Petr Skocik's user avatar
0 votes
1 answer
732 views

Compile C++ in vim

I want to make a shortcut for compiling C++ file. I use :map <F5> :!g++ % -o app && ./app <CR>. How can I edit it to set output file's name, C++ file's name without .cpp instead of ...
Reza Hosseinzadeh's user avatar
0 votes
1 answer
16 views

Move the caret to proper indentation inside insert mode in C files when using arrow keys

In insert mode, scope indentation is not taken into account if I navigate rows during insert mode. Example: In such a case, if I would press the up arrow key, Vim would place my caret at the start of ...
daedsidog's user avatar
  • 153
-1 votes
1 answer
365 views

Insert C/C++ loops and statements templates automatically [closed]

How do I insert C/C++-type loops and statements templates automatically in Vim?
Geremia's user avatar
  • 966