All Questions
291
questions
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?
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 ...
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 ?
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 ...
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 ...
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 ...
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?
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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?
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 ...
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 ...
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 ...
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 ...
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 ...
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, ...
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, ...
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 ...
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 ...
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 ...
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 ...
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->[...
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/...
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 ...
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 ...
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?
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
:...
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 ...
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 ...
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 ...
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?
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 ...
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 ...
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 ...
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);...
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 ...
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 ...
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?
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.
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 ...
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?
//
/*
*/
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 ...