Friday, February 20, 2009

VIM improvements

If you have vim 7.x version, you should know that vim supports auto completion for certain languages like c, php, python, html, css, xml, javascript.

To enable autocompletion in vim, you need to create a file in your home directory

$ vim ~/.vimrc

Copy the following code into this file

autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete

And save the file.

Now open your file in vim and check out autocompletion

$ vim mycode.php

For autocompletion press Ctrl-X O. You should be getting a dropdown of available functions/variables and on the top of the screen a definition of the selected function.

Another thing that could be done in vim is tabs. Yup check out the following commands

:tabe oldfile.php - open oldfile.php in new tab for editing
:tabnew - open a new blank tab
:tabn - go to next tab
:tabp - go to previous tab
:tabr - go to first tab
:tabc - close current tab
:tabo - close other tabs

Coding is fun!!!

No comments: