- 论坛徽章:
- 0
|
Why Should I use VI?
A good question. vi is one of the oldest editors around yet it is still very popular today. One of the reasons it is still used is due to its efficiency as an editor. The key benefit is that you do not need to use the mouse at all when editing a document. Taking your hand off the keyboard to move the mouse to a position in the document and then moving your hand back to the keyboard is extremely inefficient. With vi, your hands never leave the keyboard.
How Do You Invoke The vi Editor
From a linux shell, type:
vi
where is the name of the file you want to edit. If the file doesn't exist, it will be created. Exiting vi is discussed below.
There are two modes to the vi editor.
Editing mode
Command mode
Edit Mode
The editing mode is quite simple. Whatever you type appears in the buffer or document. Whatever you type is echoed back to you in the buffer. Pretty simple.
To enter editing mode, hit I for insert. There are other ways to drop into editing mode, which will be explained below, but just remember I for now.
Command Mode
The command mode however is where all the magic happens. It allows you to execute a series of commands on your document to help you edit it. Whether that be moving the cursor, replacing text, finding text, or whatever; you can do it all in command mode. All without using your mouse!
When you first open a document in vi, you always start in command mode. If you are in editing mode and want to return to command mode, just press ESC.
When editing or writing a document in vi, expect to jump between editing mode and command mode often. It will become second nature after a while.
Command Mode Commands
The rest of this document will explain some of the more useful commands available in command mode.
In command mode, the following key sequences have the specified effect:
First off, these keys are essential:
h - move cursor left one position
j - move cursor down one line
k - move cursor up one line
l - move cursor right one position
The arrow keys move the cursor in vim which is what Mandriva actually installs when you install vi. So if you attempt to move the cursor with the above key codes and they don't work, then try the arrow keys.
Always remember, that if there is something you want to do in vi, there is probably a command or way to do it. Also, there is always more than one way to do something. You'll find that principle everywhere in engineering and science.
Here are some simple commands you will use in addition to the movement commands above:
i - Change into editing mode. Remember, hitting gets you back out.
dw - Delete the word or rest of the word under the cursor.
cw - This command is like 'dw' except that it drops you into editing mode upon completion.
x - Deletes the character directly under the cursor.
. - Repeat the previously executed command.
:w - Save the current file to disk ('w' stands for "write").
:q - Quits vi.
:q! - Quit vi without saving changes.
:wq - Save the current file and quit.
u - Undo the last edit or command.
-r - Redo an undo.
That is basically all you need to start off in vi.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/58679/showart_456004.html |
|