Wednesday, November 6, 2013

VIM as an IDE

Why vim? There are lots of text-editors & IDEs out there.Over last 7 years I have used several text-editors & IDEs.But for me simply I'm not a fan of IDEs.

I love the ability of customization and the lightweight of VIM over other text-editors and IDEs. If you are a newbie to VIM, you might feel uncomfortable until you get familiar with basic commands. You can find number of VIM cheat sheets here[1] to learn all VIM commands.
 
You may feel few OOTB IDE features missing in VIM, once you start to code with VIM. BIG NOOOO !!! How to browse files, how to search, search and replace, how to work with multiple files etc. I will address those further within this post.

When I want to browse project directories(file system) while coding simply use the command :NERDTree. You can download this plugin from[2] and extract the downloaded content to .vim directory located under your home directory. I'm using nerdtree 4.2.0 latest version available at the moment.After extracting you can find several directories under .vim as in following screen shot.


Thats it. Now simply open a text file from your project directory, and type :NERDTree hit enter.


You can navigate between directories/files in file-system with the use of arrow keys or with the mouse and select files by hitting enter. This plugin is really helpful when you are working with a huge code base within your project.

Now lets move to the find/replace in VIM, following are few commands we can use.
/text      - search for text
?text      - search backward for text
n          - repeat search in same direction
:%s/old/new- replace all old with new throughout file
Lets talk about syntax highlighting ability of VIM now. At the moment I'm working on WSO2 Enterprise Store project which written on top of the WSO2 Carbon platform. If you browse though this product you can find that VIM needs to coupe with number of file types here. For eg :- .jag (jaggery.js file extention), .js, .hbs, .css etc.

For unknown(unknown to VIM) file types like .hbs you can enable syntax highlighting(as HTML in my scenario) by simply adding, au BufReadPost *.hbs set syntax=html  to your .vimrc. You can find .vimrc under your home directory.

Before enabling syntax highlighting for .hbs file format,


after enabling syntax highlighting,


And the best thing is that this VIM configuration is so portable, you only need to replace default .vimrc with your customized version in any distribution.

You can download and install VIM from here[3].

[1] http://www.worldtimzone.com/res/vi.html
      http://www.fprintf.net/vimCheatSheet.html
[2] http://www.vim.org/scripts/script.php?script_id=1658
[3] http://www.vim.org/download.php

No comments:

Post a Comment