Joy precedes competition.

Game && Jaguareins

Vim Rocks!

with 2 comments

Last exam is on 20th and the last one was on 10th. A good gap of 9 days to live my way. I and a friend of mine decided to work on a project, for which we need to send a proposal by 31st of December. But rather than working on it, i started a new thread of writing an image viewer using Qt. Qt is a framework for developing graphical user interface by Trolltech(Trolltech is now owned by Nokia). It supports quiet a few languages like C++, Java, Python.
It is a very basic image viewer which displays a pre-defined image. Here is a screen-shot of it displaying Princess Diana…i, my mom and my aunt are a great fan of hers.
Here is a list of files which made it:
0.) main.cpp
1.) MainWindow.h
2.) MainWindow.cpp
3.) ImageViewer.h
4.) ImageViewer.cpp

While writing a program, the programmer has to go through edit-compile-run a lot many times. Which is really frustating when you spend most of your time staring at the screen. A solution is, using an IDE(Integrated Development Environment), like Eclipse or NetBeans. But i cannot use any because my Eclipse doesnt save the changes you make, and NetBeans doesnt support C++. Too lazy to fix them up. So i went for vim, which is my favorite text editor. It is actually vi improved, a programmer’s editor, as the man page puts it. It really rocks. At first i used at least 5 instances of vim, one for each file, and the main.cpp one for switching with the terminal. But after some time i got a better solution.
Two things of vim really helped me a lot.
0.) tabs
1.) vertical splitting

You can create a new tab in vim by executing the command :tabnew. Switching between the tabs can be done by pressing the keys combination gt, to go to the next tab and gT, to go to the previous tab. Here are the screenshots showing tabs.

Another cool feature is the splitting. You can split the current window into two(or more) by issuing the command :vsp. Which stands for vertical splitting. Horizantal splitting can be done by issuing the command :sp. Switching between the splitted frames can be done using ctrl-w, in both the above mentioned cases.

Few interesting things worth mentioning are:
0.) line numbers can be displayed by -> :set nu, to unset use :set nonu
1.) spaces covered by tabs can be set by -> :set tabstop=x, where x is the number of spaces covered on hitting the tab key.
2.) syntax highlighting can be achieved by -> :syntax on, well…on many vim programs i got the message that: “E319: Sorry, the command is not available in this version”, for that you need to install vim and vim-runtime, which can be done easily using the synaptic package manager. After installing these packages, the above mentioned command works.
3.) to jump to any line say 4, just do :4 <return>
4.) a lot of color schemes can be used like blue, slate, torte, zellner to name a few. You can set any by executing the command-> colorscheme x, where x is the color scheme you want to use. To know what color schemes you have, after typing :colorscheme just tab around, which will subsequently show you the name of the theme.

All these are temporary, which means they go off as soon as you close you terminal. To make them permanent, put them in a file named .vimrc, and place thee file in $HOME. .vimrc is the configuration file for vim.

Vim is really a cool text editor. Initially one might feel that it is difficult to learn, but once you start grasping it, it is really difficult to stop you from falling in love with the editor. For those who love working on GUI, there is a graphical substitution for it, namely gvim. Vim is also out there for windoze.

Some references:


Written by LaFolle

December 14, 2008 at 20:59

Posted in Uncategorized

2 Responses

Subscribe to comments with RSS.

  1. Great work.

    Vikas Choudhary

    December 15, 2008 at 14:02

  2. fan of Princess Diana….well are you seriuos??


    January 2, 2009 at 20:51

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: