Sunday, October 18, 2009

VI Improved - Tutorial

Share Orkut

How many people using unix like system do you think, have atleast a basic knowledge of using one of the most powerful editors of the platform? There are many who don't like to use VIM, purely due to its 'UN-GUI'ishness; they tend to go in for other simple to use and comparatively less geeky alternatives like 'nano'. What will you do when you are faced with a scnerio where there are no options other than using it ?

This tutorial aims to let you understand the extremely basic stuff you should know about VIM; bewarned that this is not even worthy of being mentioned as the 'Tip of the Iceberg'. VIM is an extensive tool which might take months to master.

To start VIM & open a file, say 'new.txt'; we type the following at the terminal,

'vim new.txt'

now you will see the contents of the file new.txt on your screen, at the last line will be written, "new.txt" 9L, 45C; this means that the filename is "new.txt" having 9 lines of data & size 45bytes (1 char {C}= 1 byte). This mode is called normal mode or command mode.

Now you want to edit the file, go to the character from where you would like to 'insert' text and press either 'a' or 'i'. If you press 'a' the cursor will advance 1 character forward and start inserting and if you type 'i' the cursor will start inserting at the current position. This mode when you insert data or text is called as 'insert' mode, to come out of the insert mode to the command mode, press 'Esc' key.

If you wish to delete some text then follow the same steps for editing to enter the 'insert' mode and use 'Backspace' key to delete charecters, again using 'Esc' key to exit the 'insert' mode and enter the 'command' mode.

Now that you have edited the file, you have to options; either save the changes done to the file or discard the changes and quit VIM.

To save a file type ':wq' in the 'command mode', (Note: - ':wq' will not work in the insert mode), if you want to save the file with another name use ':W FILENAME' in the 'command' mode, but in this option VIM will save the file with the name you specified and continue to edit the old file, and another command is ':saveas FILENAME' which is the same as ':w FILENAME' but it will now edit the new file after saving.

To quit the VIM editor use the command ':q', which is only allowed if the file has not been modified. If you wish to discard the changes and quit type ':q!'.

These are just 'dirt basic' that you need to know if you are going to use a Unix machine, VIM is too extensive to be covered in a few blog posts. Hope it helps even if its a bit. If you have any queries, feel free to post them as comments and I will surely try to clarify them.

0 comments:

Post a Comment

Write your comment here