Friday, January 22, 2010

Vim as IDE

I've discovered that it seems quite feasible to set up the VIM text editor as an Integrated Development Environment for C++ programming. This is exciting because it's a lot smaller and faster than most full-featured (i.e. bloated) IDEs, is the best programmer's editor (in my opinion), and allows me to do programming in Linux without using Eclipse (which takes an enormous amount of resources). The software you need to put this together is as follows:

gvim, of course.

gcc, of course, to compile C++ code.

make, for writing a "project" that lets you add your source files and get compiled into your program with one command.

ctags, so that you can jump from a variable's use to its declaration with Ctrl+] (and then jump back with Ctrl+t), and as a prerequisite for code completion (see below).

yavdb and gdb. yavdb lets you do debugging in vim by attaching gdb to an existing vim window. Then you can use the function keys in your code to set breakpoints and step to lines of interest, and press F10 to see the value of the variable under the cursor. When you want to examine more complicated information, go to the terminal you started yavdb from and use gdb commands. Simple and quite effective.

omnicppcomplete, which does code completion in vim by using your tags file generated by ctags. There are some slightly involved (but straightforward) instructions involved in setting it up, but I had no trouble getting it to work. Once it's set up, you get a list of member choices whenever you press ., ->, or ::.

Finally, you'll probably want to set / remap some shortcut keys so the function keys do what you want. For example, to set keys for building the project, and going to the next / previous compilation error, add lines like these to your ~/.vimrc file:


map <F4> :make<Return>
map <F6> :cnext<Return>
map <S-F6> :cprevious<Return>


which sets F4 to build your project, and F6/Shift F6 to go to the next / previous compile error.

No comments:

Post a Comment