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!
June 4, 2006 at 9:27 am
Ctrl-p was in vim 6 as well. Omni-complete is Ctrl-X Ctrl-O
June 4, 2006 at 6:55 pm
vi as in “vicious interface” ?
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.
June 13, 2006 at 11:14 am
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\+$”