What is Your C Development Environment like?

4 points by lambdaman ↗ HN
Let me explain my problem:

Say I want to start looking at the source of a C project. First thing I do is highlight all the .c/.h files in the folder (ctrl + click and so on..), right click, select "open all with GVim". The script opens all .c and .h files in GVim in separate tabs each. After that, I resize the GVim window to leave some space for a terminal to run make/gcc/gdb/git etc. At this point, I'm ready to look at some code.

Browsing through code is not easy mainly because of the tabs. In this project that I'm looking at, there are 10+ files and I know that's not even a lot. I have to keep hitting 'gt' or 'gT' if I want to go to a certain .c or .h file and it's a nightmare if you have 10+ tabs open.

So, HN what is your environment or workflow like when coding in C? Any tips on how I can make my environment better?

Here's my environment right now:

Laptop 15.6" screen Ubuntu 10.04 GVim (NerdTree, Taglist, ctags) Terminal for (gcc, gdb, make, git)

GVim and Terminal are side by side.

8 comments

[ 3.3 ms ] story [ 27.3 ms ] thread
first off needs

libstdc++.so.6 or something similar

on windows its in visual studio 2008, mac its xcode 4.x

other than that stuff i don't worry too much about detail and focus on making great programs that make me $

I usually use vim+screen+make(gdb, gcc...). Plus a really hairy .screenrc that does some magic to put running command lines in the status line (so i can see which screen has vim foo.c running). But the key is to not have 10+ files open at once. You're using vim so opening and closing vim instances is no big deal. I usually only have two or three source files open at a time that way i know exactly where each one is. This limits my screen tabs to only 4-5 which is pretty manageable.
I usually have a konsole open ready to run make; and two kwrite windows open, side by side. Sometimes also a konqueror window open to the directory containing the source code I'm working on at the time.

As lukesandberg points out, there's no reason to have 10+ files open at once. Work on one thing at once and only open up files when you're working on them or need to check something (e.g., "what order did I put the parameters to that function").

I use Emacs with all of the ido stuff. Even with dozens of buffers open, I can just hit C-x b and then a couple of characters in the name of the buffer I want. I don't even have to use consecutive character; 'fb' would work to match 'foobar.txt'.

You can have a shell in an Emacs buffer, but I could never really get used to that. Instead, I use Tilda to have a Quake-style console that I can show or hide as I need.

I don't do much C myself but I use Vim all the time so maybe I can give you a few useful hints:

- learn to open files from Vim with :e and tab completion

- learn to use buffers effectively, the :b command with tab completion is particularly useful to switch between buffers

- CRTL-0 / CTRL-I to go back and forth between cursor positions

- for C/C++, a.vim is a plugin that allows you to switch quickly between header and implementation

- learn to use make from Vim with :make, it will take you to the first compilation error and open a quickfix window that you can use to go to other errors (can be configured to compile other languages than C/C++)

- try ack, a better grep, very useful to search source code, there's a Vim plugin to integrate it

- if you have a lot of files and directories in your project, try the Command-T plugin

- for git, the Fugitive plugin can also be helpful (screencasts at http://vimcasts.org/)

A random guess at the real problem: you have not found a way to efficiently navigate multi-file projects, and thus end up opening tons of tabs. I was going to recommend ctags, but apparently you've already found it (you know about the extremely useful Ctrl-], Ctrl-t?); I've heard people recommend cscope (although I wouldn't run it on untrusted source code), and I'm sure there are other options. If this is indeed the real issue, try to fix that first.
This is exactly why I find using an IDE (MSCV / XCode) so attractive when working in C or C++, I'm sure others would agree too. It makes you lazy (ignorant?) about makefiles and the build process unfortunately, but increases productivity for me when I can easily view the whole project in terms of files OR classes/code constructs.

I'm also a fan of TextWrangler on the Mac for its basic file sidebar for quickly switching, but its still a bit tougher on big projects, having only a "flat" view of your files.