The first version of VI was written by Bill Joy in 1978, when he was a UC Berkeley student. Later he co-founded the Magical Sun Company. VI is derived from the word visual, the goal is to visually simulate the editing of text on the terminal, is more humane. Because the use is still not very convenient, later Bram Moolenaar did the improvement, becomes VIM (vi improved), because obtains the very big promotion, so now most Linux distribution installs the VIM.
Why use VIM, because people spit groove, criticized a pile, but that is the idea of rookie. Imagine when the system crashes, how to write files, restore the system, and finally really only through vim to edit the script. For beginners, how much to know the order of vim, will not be superfluous. VI command A large number of, to remember really want to repeat the connection, the actual use of the command is very few, here Luo listed some of the commonly used VIM commands.
The basic steps of Vim's text editing are to start vim, edit text, save text, and exit vim. The following is a brief description of the relevant commands.
1. Start vim
To start vim, simply enter the VI or VIM command, and the command is as follows:
Vi
或
$ vim
或
$ vim Testvim.txt
Will output the following results
VIM - Vi Improved....
2. Edit Text
Vim has two modes, the editing mode and the command mode, when VIM starts the default command mode, when in the editing mode, you can switch to the command mode by the ESC key, in the command mode, the user can enter the relevant commands to complete the corresponding operation, such as the completion of the cursor movement, file saving and program exit and other operations.
2.1. Insert mode
Press the "I" key to enter insert mode. After that, we should see the following line at the bottom of the screen if Vim is running in advanced mode (this does not appear in Vim compatibility mode):
-- INSERT --
Now we can enter some text. Try entering the text:
Hello world, I am testing VIM text editor
Press the ESC key to exit Insert mode and return to command mode.
2.2. Cursor movement
VI provides a number of move commands, some of which are shared with the less reader, some of which are shown in the following table:
Key |
Move Cursor |
L or RIGHT Arrow |
Move one character to the right |
H or LEFT Arrow |
Move one character to the left |
J or DOWN Arrow |
Move down one line |
K or UP ARROW |
Move up one line |
0 (0 keys) |
Moves to the beginning of the current line. |
^ |
Moves to the first non-empty character of the current line. |
$ |
Moves to the end of the current line. |
W |
Move to the beginning of the next word or punctuation. |
W |
Moves to the beginning of the next word, ignoring punctuation. |
B |
Move to the beginning of the previous word or punctuation. |
B |
Moves to the beginning of the previous word, ignoring punctuation. |
Ctrl-f or Page down |
Turn down one page |
Ctrl-b or Page up |
Turn up one page |
Numberg |
Move to number line. For example, 1G moves to the first line of the file. |
G |
Moves to the beginning of the end of the file. |
2.3. Delete text
Delete the contents of the text, the following commands are not recognized:
Command |
deleted text |
x |
The current character |
3x |
|
dd |
current row. |
5dd |
|
DW |
|
d$ |
|
d0 |
|
d^ |
|
DG |
from the current line to the end of the file. |
d20g |
from the current line to the 20th line of the file. |
2.4. Copy, cut and paste
Copy, cut and paste the contents of the text, and some of the commands are as follows:
Command |
copied content |
Yy |
The current row. |
5yy |
The current line and the next four lines of text. |
YW |
From the current cursor position to the beginning of the next word. |
y$ |
From the current cursor position to the end of the current line. |
Y0 |
From the current cursor position to the beginning of the line. |
y^ |
The first non-null character from the current cursor position to the line of text. |
YG |
From the current line to the end of the file. |
y20g |
From the current line to the 20th line of the file. |
3. Save Text
Switch to command mode, by entering: key, after pressing the colon key, a colon: character should appear in the lower left corner of the screen, we then enter the W character (write) after the colon, if saved in a known file, you do not need to enter the file name. Then press ENTER to enter:
: W
Or specify a file name to save
: w testvim.txt
The file will be written to the hard disk, and we should get a confirmation message at the bottom of the screen, like this:
"testvim.txt" [New] 1L, 42C written
4. Exit Vim
To exit Vim, enter the following command (note that the colon: is part of the command):
: Q
The shell prompt should be returned. If for some reason, VI cannot exit (usually because we have modified the file but did not save the file). By adding an exclamation mark to the command, we can tell VI we want to force exit VI. The command is as follows:
: q!
Resources
1, VI Introduction
Linux knowledge (5)----VIM