Saturday, March 10, 2012

A winning Combination


I have been working with Vim "text editor" for some time now. I found a few helpful entries I'd like to share. These helpful tips and tricks helps me be more efficient, code faster and makes the very powerful Vim even stronger.

First of all - install Vim and learn how to work with it (took me a while, but totally worth it).
 
The first cool add-on: snipMate (super easy to install) check it out

a short feature that show just the tip of the iceberg

Than i found some cool new features that actually transforms Vim editor in to an IDE altogether.

basically you need to run these commands:

$ git clone https://github.com/sontek/dotfiles.git
$ cd dotfiles
$ ./install.sh vim 

unfortunately the both (snipMate and Pathogen) don't work well together, this is just a challenge for me, there is no way I'll give up and just choose one. 
So I looked for a way to combine the two.
The trick was, installing them in the right order, snipMate then Pathogen (although you can mess around with it to find your way).
and then follow this little patch, to fix this small twitch, regarding mapping a different key <Ctrl+j> to activate snippet instead of <tab> to allow the both to co-exist.

Any way, the real cool thing about these features is that you can easily modify and adapt them to your needs. writing new code snippets, changing text highlighting, customizing auto-completions and syntax checking can be super helpful and is super easy to do.
 you can create your very own customized, "free of Charge",flexible and "free spirited" IDE.

For example:
writing a new code snippet for "*.xml" filetype:
simply write a new file named "xml.snippets" and place it in "~/.vim/snippets/"
(or equivalent, e.g. $HOME\vimfiles on Windows), edit the file and add (for the example sake) this code:
snippet version
            <?xml version="${1:*.*}"?>
snippet <>
            <${1:TagName}>
            </${2:TagName}>

this is what it does (I'll let you do the simple revers engineering):
but the guidelines are "${1:text}" - the first variable the marker will enter when snippet key  (in my case <Ctrl+j>) is hit.




* the video is a bit fuzzy but ... you'll get the picture :)
In future entries I'll try summarizing all of my insights in customizing Vim.
let me know what you think ... i feel this work was life changing (seeing that i suck in getting syntax correct the first time).

- Cool fact: "*.snippets" filetype has snippets (recursive ?) -

G.

No comments:

Post a Comment