All Questions

Tagged with
Filter by
Sorted by
Tagged with
305 votes
10 answers
231k views

How can I autoformat/indent C code in vim?

When I copy code from another file, the formatting is messed up, like this: fun() { for(...) { for(...) { if(...) { } } } } How can I autoformat this code in vim?
Yongwei Xing's user avatar
  • 13.2k
92 votes
7 answers
132k views

Auto-indent spaces with C in vim?

I've been somewhat spoiled using Eclipse and java. I started using vim to do C coding in a linux environment, is there a way to have vim automatically do the proper spacing for blocks? So after ...
zxcv's user avatar
  • 7,531
69 votes
14 answers
99k views

How do I run a C program from VIM?

Is there a way to compile and run a C program from VIM without typing its filename ?
Coder's user avatar
  • 699
31 votes
6 answers
27k views

Vim [compile and] run shortcut

Basically what I want is a keyboard shortcut in vim that lets me [compile and] run the currently being edited C, C++ or Python program. In psuedocode: when a shortcut key is pressed: if ...
user avatar
31 votes
3 answers
17k views

Refactoring C/C++ in Vim (e.g. method extraction like in Eclipse)

Are there any plugins or built-in methods in Vim for performing refactoring on C or C++ code, something like the refactoring tools in Eclipse? I'm especially keen on the extract method refactoring ...
Bjarke Freund-Hansen's user avatar
25 votes
4 answers
2k views

ctags ignore lists for libc6, libstdc++ and boost

I use ctags with vim and the OmniCppComplete plugin. Currently when generating my tags I do it individually for each library. For libc6 I use the following list of tokens / macros in a file named ...
Robert S. Barnes's user avatar
24 votes
4 answers
22k views

gdb front end to use with vim? [duplicate]

What gdb frontends can I use with vim for debugging C and C++ code? Currently I use cgdb and am satisfied with it. Was just wondering what else is out there?
Letholdrus's user avatar
  • 1,261
23 votes
3 answers
7k views

How to disable vim's indentation of switch case?

I'm currently fighting with Vim, I can't seem to make the indentation options do what I want. Here are my settings, I put them at the bottom of .vimrc to make sure they take precedence. As you can ...
andy's user avatar
  • 18.2k
22 votes
2 answers
2k views

Make vim indent C preprocessor directives the same as other statements

General info (Note: Please read this all the way through, because I spent a bit of time organizing it, making sure I addressed each individual problem I'm having and why one proposed solution doesn't ...
Dr Kitty's user avatar
  • 442
21 votes
2 answers
2k views

Vim different textwidth for multiline C comments?

In our C++ code base we keep 99 column lines but 79-some-odd column multiline comments. Is there a good strategy to do this automagically? I assume the modes are already known because of smart comment ...
cdleary's user avatar
  • 70.6k
20 votes
2 answers
2k views

Turn off vim syntax highlighting inside C++ comments

I recently downloaded vim 8.0. I don't know if I messed something up or a default changed, but in this code... int foo() { // This is a comment containing a "string" and the number 5. return ...
Michael Kristofik's user avatar
18 votes
3 answers
12k views

Can i go to the error after executing make in VIM?

Can i go to the line of error , while compiling a C or C++ project ? Usually by executing make , and parse the error string , and go to the specific file , and the line with errors. Is there already ...
daisy's user avatar
  • 23k
17 votes
2 answers
24k views

How can I use gcc's -I command to add recursive folders

Is there a way to use gcc's -I command and add all the paths to search path by giving a root directory? I'm trying to use :!gcc -E myfile.c to view macro expansions, but myfile.c includes a whole ...
shengy's user avatar
  • 9,621
15 votes
8 answers
162k views

What is newline character -- '\n'

This is a very basic concept, but something I have never been able to articulate that well. and I would like to try to spell it and see where I go wrong. If I have to, how would I define a "newline ...
xyz's user avatar
  • 8,807
15 votes
1 answer
27k views

How to configure .ycm_extra_conf.py for current project include PATH

I installed YCM and syntastic for VIM, normally they work fine, but I have problem when it detect some errors in my code, it shows that can NOT find some head files(which is my project head file). My ...
How Chen's user avatar
  • 1,340
14 votes
8 answers
9k views

gvim and gdb for C?

In emacs there is a handy way to launch the gdb and gui options for gdb, the C debugger. Is there a similar option in gvim?
zxcv's user avatar
  • 7,531
13 votes
2 answers
2k views

How to find struct member uses with cscope and ignore local variables?

I'm using cscope for a large project with vim, but without the vim mappings (they froze vim for some weird reason). I'm using cscope commands from within vim, and I want to be able to find uses of ...
Diego Medaglia's user avatar
12 votes
3 answers
6k views

Vim Keyword Completion

How do I tell the Vim editor about my include files path so that it can auto complete the function names when I press CTRL+N? For example, I have a C program like below: #include<stdio.h> int ...
chappar's user avatar
  • 7,325
11 votes
3 answers
27k views

How to find the callers and callee of a function in C code in vi/vim?

I want to know how can I easily click (or maybe use some easy shortcuts) on a function name and find all its callee or open where it has been defined. Most of the web manuals in web are really hard to ...
Mona Jalal's user avatar
  • 36.5k
11 votes
2 answers
15k views

cscope: How to use cscope to search for a symbol using command line?

All the cscope tutorials I found online talk about how to use the interactive mode of cscope to search for symbols in editors such as vim and emacs. But I think it should be possible to issue a ...
kakyo's user avatar
  • 11.1k
11 votes
2 answers
7k views

vim :make to compile and run C code if it's a success

to compile C programs and run it, I use ":make" but I would like to run the compiled program too if the compile is a success. I wrote au FileType c setlocal makeprg=g++\ %\ \&\&\ ./a.out in ...
Gilles Quénot's user avatar
11 votes
3 answers
20k views

Vim + YouCompleteMe + C: a minimal .ycm_extra_conf.py?

I've already got Vim with YouCompleteMe plugin (compiled with semantic support for C-family languages), which I use for Python etc. Now I'd like to try it with C (I've never developed with C before, ...
kekkonen's user avatar
  • 459
11 votes
2 answers
2k views

Vim auto-indentation: Align an array initialization which extends over multiple lines

Sometimes an array initialization in C extends over several lines, especially if the array is multidimensional. In Emacs the result of auto-indentation looks like this: int a[N][N] = {{0, 0, 6, 7, 0, ...
qfab's user avatar
  • 175
11 votes
1 answer
2k views

Vim - Show data type

I typically code most of my C projects in Vim. I am comfortable with navigation, search and replace, and indexing via Ctags/Cscope. One feature I would like to have, if possible, is a keymapping that ...
Cloud's user avatar
  • 19.1k
10 votes
6 answers
3k views

Is there any cure for the preprocessor blues?

I know that I can kick the the preprocessor to spit out output with the -E option in my particular circumstance. For generated code this preprocessor output is murderous. For example I have a 4gl ...
ojblass's user avatar
  • 21.4k
10 votes
1 answer
4k views

scope vs ctags in terms of features

I am a big fan of ctags Hence I am wondering if I have cscope, will I benefit more there two programs. Seems like the latter has the same features as ctags, namely, facilitating the finding of ...
vehomzzz's user avatar
  • 43.7k
10 votes
1 answer
11k views

YCM does not find my headers?

I have the following folder structure: . ├── include │   └── ctset │   ├── hashtable.h │   └── set.h └── src └── hashtable └── hashtable.c And in hashtable.c the include #include ...
musicmatze's user avatar
  • 4,230
9 votes
9 answers
2k views

Speedup writing C programs using a subset of the Python syntax

I am constantly trying to optimize my time. Writing a C code takes a lot of time and requires much more keyboard touches than say writing a Python program. However, in order to speed up the time ...
9 votes
1 answer
7k views

Vim autocomplete a struct in C

I'm trying to use Vim autocomplete. I've got a struct in file def.h: typedef struct test{ int x; int y; }*test_p,test_t; And in the corresponding C file: test_p t; t->[...
JosipBros's user avatar
8 votes
3 answers
4k views

How to jump to a C/C++ function declaration instead of its definition?

I know CTRL+] to jump to definition of a function in various languages in vim. What about jump to declaration in C/C++ header? Since I have plenty of headers containing meaningful comments/...
Keisau CHING's user avatar
8 votes
1 answer
2k views

VIM: Certain .c files opening without syntax highlighting

I have some .c files that don't automatically highlight in vim. This problem only recently started. I have not edited my .vimrc file: set number nnoremap <F2> :set nonumber!<CR>:set ...
dcpomero's user avatar
  • 999
8 votes
3 answers
3k views

How can I teach vim about additional C language types for syntax highlighting?

Syntax highlighting works swimmingly beautiful with the standard types, like int, uint32_t, float and so on. However, I would like to teach vim that there are other types defined with typedef in my ...
Jens's user avatar
  • 71.2k
7 votes
6 answers
12k views

How can I automatically fold a long C code in Vim?

I regularly run into C-codes without folding. It is irritating to read them if there is no folding, particularly with long files. How can I fold them?
Léo Léopold Hertz 준영's user avatar
7 votes
7 answers
4k views

What are most useful/used vim commands in C/C++ dev environment [closed]

Here is the list of mine Unlike me -- as I did it for illustrative purposes -- don't paste too many. And most importantly, provide an explanation Commands shouldn't be generic but relevant to C++...
7 votes
1 answer
14k views

Ideal C Setup for Vim

I'm trying to set up a fairly traditional environment for C programming in Vim just to get a taste of it coming from a graphical IDE background. Currently my .vimrc file looks like this: syntax on :...
user1427661's user avatar
  • 11.5k
7 votes
1 answer
5k views

How to fold C code with vim?

I've been trying to explore code folding options in Vim, and I have stumbled upon this stack-overflow question. While I have been able to put that into my vimrc, the problem I'm having is that it ...
chutsu's user avatar
  • 13.8k
7 votes
1 answer
1k views

when should we care about cache missing?

I want to explain my question through a practical problem I met in my project. I am writing a c library( which behaves like a programmable vi editor), and i plan to provide a series of APIs ( more ...
weiweishuo's user avatar
7 votes
3 answers
4k views

How to setup YouCompleteMe for kernel and device driver development?

I would like to setup vim for kernel hacking so I have installed YouCompleteMe for auto completion. However, no matter what I do It looks like I can't configure it properly. It does not do semantic ...
max's user avatar
  • 2,647
7 votes
2 answers
2k views

I like c.vim plugin, but I don't use K&R code style

When I write code, I'd like to use ANSI C style, but the code style in c.vim template is K&R. Where can I get another template or any other plugin instead of c.vim?
Yucoat's user avatar
  • 193
6 votes
3 answers
2k views

How do I compile C programs using Vim's 'make' command with Visual Studio's compiler on Windows 7?

I'm trying to set up Vim to user VS (express) C compiler cl.exe. Adding set makrprg='c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl.exe' (I've tried escaping with \\, \\\, \\\\ just ...
gvkv's user avatar
  • 1,906
6 votes
1 answer
1k views

VIM open compile error in existing or new tab

When I compile or run a file from VIM all error references are opened in the last active buffer regardless if the file is open already in another vim tab. This behavior is very annoying. Is there any ...
Peter's user avatar
  • 63
6 votes
1 answer
885 views

Snapshot of a part of a file in Vim: hide comments and blank lines

How to temporary show a snapshot of a file, while hiding comments and blank line? The purpose would be to get a catch of a C++ function (for example), in a dense page formating. A manner to do that ...
nojhan's user avatar
  • 1,282
6 votes
1 answer
329 views

Why does vim crash when it becomes an orphan process?

#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/wait.h> int main() { int pid = fork(); if (pid) { sleep(5); // wait(NULL);...
StackExchange123's user avatar
6 votes
1 answer
9k views

Using multiple tag files at once in vim / Tag organisation in general

(Apologies for the C tag, I did it for the syntax highlighting. This is more of a vim question. If someone more learned than I thinks the tag should be removed please do so) Say I've got this ...
TheIronKnuckle's user avatar
5 votes
5 answers
13k views

what is the good gvim guifont for C/C++ programming [closed]

I am trying to find an optimal font for gvim to program in C/C++. I currently have the following in ~/.gvimrc and I don't like it: if has("gui_gtk2") set guifont=MiscFixed\ 11 else set ...
vehomzzz's user avatar
  • 43.7k
5 votes
4 answers
4k views

How do you use markers in vi?

I just discovered the existence of markers in vi. How do you use it, what do you know about them? are they useful, say for a C++ developer?
vehomzzz's user avatar
  • 43.7k
5 votes
1 answer
4k views

Appearance of split lines in vim [closed]

I would like to change the appearance of the vertical split division, which currently uses |. Is there a Vim setting, or can it be modified in the source code? Please give me some tips.
prehistoricpenguin's user avatar
5 votes
3 answers
1k views

How to get rid of GVim folding comments in your code?

There is someone in my team that swears by using some kind of GVim feature to do manually code folding. As I'm using another editor and do not really need the folding feature, I think it only ...
Roalt's user avatar
  • 8,370
5 votes
4 answers
5k views

In vim, how to remove all the C and C++ comments?

How to remove all C and C++ comments in vi? // /* */
Chiakey's user avatar
  • 131
5 votes
1 answer
164 views

How to make comment around a line of description using vim?

I thought it would be handy to create a mapping that would turn the current line or visually selected line into a comment banner. Something like this: This is the description of the usage of the ...
mko's user avatar
  • 21.7k

1
2 3 4 5 6