December 29, 2007

VI text editor :) part1

What is vi? Why does anyone use it? More importantly, why should I use it?

vi is default editor under Unix/Linux, and is therefore shipped with all recent version of Unix/Linux.
This means that whenever you run across a machine that is running a Unix of some sort, you will know that you have a powerful editor at your finger tips.

Why else?

vi is a powerful editor. Also, once you know vi, you can edit files really quickly, as it is extremely economical with the keystrokes.

Due to its different modes for inserting and issuing commands, it is much faster than most non-mode based editors.
It is also a very small editor. Also, it can do almost anything, as long as you know how to get it to do what you want

Wow! This sounds great! Is there any reason not to use vi?

Yes. There is a very good reason. It can be somewhat hard to learn, and until you do so.
it will be slow and painful. Once you learn it, it will be faster, but the process of learning it is slow.
I've been asked if vi was an easy editor to learn?

My general response to this question is:
"Yes, some of us think so. But most people think that we are crazy."


The 3 Modes of VI

The first thing most users learn about the VI editor is that it has 3 modes:

command, insert and excute.
1 - Command Mode
allows the entry of commands to manipulate text.( copy , delete ,past , cut ...etc )
These commands are usually one or two characters long, and can be entered with few keystrokes.

2 - Insert Mode
puts anything typed on the keyboard into the current file. (insert text ...etc )

3 - Excute Mode
Commands Used to (save , quite , search , load file ... etc )

================

VI starts out in command mode. There are several commands that put the VI editor into insert mode.

The most commonly used commands to get into insert mode are (a and i). These two commands are described below.

Once you are in insert mode, you get out of it by hitting the escape key.
If your terminal does not have an escape key, ^[ should work (control-[).

You can hit escape two times in a row and VI would definitely be in command mode.
Hitting escape while you are already in command mode doesn't take the editor out of command mode. It may beep to tell you that you are already in that mode.

to use excute mode
- from command mode typethe ":"befor the commands


=======================================================
How to Type Commands in Command Mode ?

The command mode commands are normally in this format:(Optional arguments are given in the brackets)

[count] command [where]

Most commands are one character long, including those which use control characters.
The commands described in this section are those which are used most commonly the VI editor.

The count is entered as a number beginning with any character from 1 to 9. For example, the x command deletes a character under the cursor. If you type 23x while in command mode, it will delete 23 characters.

Some commands use an optional where parameter, where you can specify how many lines or how much of the document the command affects, the where parameter can also be any command that moves the cursor.

No comments: