Fotis’ blog

Blooooooog

C editing with vim

Posted by Fotis on June 3, 2006

I believe that the best editor for a programmer is vim. I have used it for quite some time and i found that all those features can make your life really easy. Some settings that may help you are the following.
First some general stuff:

set nocp
set number
set ruler


My coding style is softtabs and each tab is 2 spaces. So for some help for the indentation i use the following:

set cindent
set expandtab
set shiftwidth=2
set tabstop=2


Another very good feature of vim is syntax (for highlighting, folding, etc). The settings i use are:

syntax enable
” I hate spaces at the end of a line so i want to highlight them.
syntax match Error “\s\+$”

For the folding i always use the syntax method. I also made some mappings that help me with fold open/close:

set foldmethod=syntax
syntax sync fromstart
” Never fold at the beginning
set foldlevelstart=99
map zo
map zc
map zR
map zM


These are my general settings.
Apart from these i use some plugins. A programmer must have the taglist plugin. It is a source code browser for your programs. It creates a window with all functions, variables, macros, etc that you have at your program and you can jump anywhere you want anytime. To use it you must also have the exuberant ctags utility, but you’re a programmer, you should have it! A mapping that i use is

map :Tlist


that allows me to open the browser at anytime by just pressing F11.
Another plugin that i have installed is the c reference plugin. It has a complete c reference and you can find info about any command and any function at the standard c library by just using some keystrokes. To be honest i never needed it but you may find it usefull :)
Finally i would suggest you to get vim7, the latest vim version. It has an autocomplete feature (try typing pri and press Ctrl-p !), it’s syntax for c is much better and it has many many other improvements.
I think that’s all. I wrote this while watching an episode from a known tv series where jac^H^H^Hgod saves earth for the fifth time in five days (more to come about this in a new post). If i find something else or if there is a bug i’ll post again about vim :)

Update: As dado1945 pointed out ctrl-p was in vim 6 too, only omni-complete was added. Sorry, i didn’t know this :) But the menu was added in vim 7!

4 Responses to “C editing with vim”

  1. dado1945 Says:

    Ctrl-p was in vim 6 as well. Omni-complete is Ctrl-X Ctrl-O

  2. Beket_ Says:

    vi as in “vicious interface” ? :P

    Although I only use vi sporadically, I do agree that it’s a nice piece of software.

    Hey fotis, great blog! Keep on supplying us with interesting articles.

  3. Aggelos Orfanakos Says:

    Great post! I don’t know why, but

    syntax match Error “\s\+$”

    didn’t work for me so I had to replace it with

    autocmd Syntax * syntax match Error “\s\+$”

  4. Arslanlar Şehri » Linux manpage sayfalarındaki C fonksiyon bilgileri Says:

    [...] http://fotisl.wordpress.com/2006/06/03/c-editing-with-vim/ http://www.justlinux.com/nhf/Programming/Introduction_to_C_Programming.html http://www.linuxjournal.com/article/8289 [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>