Before you start using Vim editor we first introduce the Vim mode.
1 vim mode Introduction
Vim and vi, as only these modes are switched in the keyboard. This makes Vim can not be a menu or mouse operation, and the operation key combination is minimized. It can greatly enhance the speed and efficiency.
Vim has six basic modes and 5 derived model, we here only briefly under six basic modes:
- Normal mode (Normal mode)
In the normal mode, with the editor commands, such as moving the cursor, deleting text and the like. This is also the default mode is activated after Vim. This goes and look forward to many new users reverse mode of operation (most editors insert mode is the default mode).
Vim comes from its powerful editing can Normal mode commands. Normal operation mode commands often need a TAIL. E.g. normal mode command
dd
to delete the current line, but after the first "d" may be with the other movement command instead of the second oned
, for example by moving to the next line of the "j" key to delete the current and next line. Further commands can also specify the number of repetitions2dd
(repeateddd
twice), anddj
the effect is the same. Users learn to move between the various text / jump command and the other editing commands of the normal mode, and the flexibility to use a combination of words, text can be edited more efficiently than those without a schema editor.In the normal mode, there are many ways to insert mode. More common way is to press
a
(append / addition) or keyi
(insert / insert) key.
- Insert mode (Insert mode)
In this model, most of the keys are inserted into the text in the text buffer. Most of the new text editor to edit the user wishes to remain during this mode.
In insert mode, you can press the
ESC
key to return to normal mode.
- Visual mode (Visual mode)
This pattern is quite similar to the normal mode. But the move command will expand the text area highlighted. Highlighted area can be a character, line or block of text. When performing a non-moving command, the command will be executed on this area highlighted. Vim "Text Object" can be used and as the movement command in this mode.
- Mode Select (Select mode)
The modal and editor of behavior is quite similar (standard mode Windows text control). In this mode, the text can be selected with the mouse or cursor keys to highlight, but then enter any character, Vim will replace the selected character with the highlighted text block, and automatically insert mode.
- Command line mode (Command line mode)
Command mode can be entered in the text it will be interpreted and executed. E.g. Run (
:
key), searching (/
and?
key), or a filter command (!
key). After command execution, Vim returns to the previous command line mode, usually a normal mode.
- Ex mode (Ex mode)
This command-line mode similar, in use
:visual
before leaving the Ex command mode, you can execute multiple commands at once.This is where we used to normal mode, insert mode and command line mode, the course content involves only three common patterns of
2 three common mode switching
[vim filename] to open the file boot into normal mode, simply press when in insert mode or command line mode Esc
, or Ctrl+[
you can enter the normal mode.
Normal mode Press i
(insertion) or a
(additional) keys can insert mode, normal mode, press :
into the command line. Command-line mode, enter wq
the Enter save and exit vim.
3 enter vim
3.1 Use vim vim command to enter interface
Vim back with the file name already exists, or you want to open the file name (as the new file) does not exist. Xfce open terminal, enter the following command
$ vim practice_1.txt
You can also open the direct use vim vim editor, but does not open any files.
$ vim
After entering the command line input :e 文件路径
can also open the file.
3.2 cursor
After entering vim, press i
enter insert mode. In this mode you can enter text information, enter the following three lines of information below:
12345678
abcdefghijk
shiyanlou.com
Press Esc
enter normal mode, in this mode, or direction keys h
, j
, k
, l
key to move the cursor.
button | Explanation |
---|---|
h |
left |
l |
Right (lowercase L) |
j |
under |
k |
on |
w |
Move to the next word |
b |
Move to the previous word |
4 into the insert mode
Use the following key in the normal mode into insert mode, and can start from a position corresponding to the input
command | Explanation |
---|---|
i |
Edited in the current cursor position |
I |
First insert the line |
A |
The insertion end of the line |
a |
Insert editing cursor |
o |
After the current line to insert a new row |
O |
Before the current line to insert a new row |
cw |
Replacement character to the end of a word from the cursor position |
Note that each must first return to normal mode to switch to a different way to enter insert mode
Save the document under command line mode 5
Normal mode from input :
into the command line, type w
Enter, save the document. Input :w 文件名
can save the document as a different file name or save to a different path
6 Exit vim
Exit vim 6.1 command line mode
Normal mode from input :
into the command line, type wq
Enter, save and exit the editor
The following is the exit several other ways:
command | Explanation |
---|---|
:q! |
Forced to exit without saving |
:q |
drop out |
:wq! |
Force Save and Exit |
:w <文件路径> |
Save as |
:saveas 文件路径 |
Save as |
:x |
Save and Exit |
:wq |
Save and Exit |
Exit vim 6.2 Normal mode
Enter the normal mode Shift+zz
to save and exit vim
7 Delete Text
Into normal mode, use the following command to delete text quickly:
command | Explanation |
---|---|
x |
Delete the character under the cursor |
X |
To delete a character before the cursor |
Delete |
withx |
dd |
Delete the entire line |
dw |
To delete a word (NA Chinese) |
d$ orD |
Delete to end of line |
d^ |
Delete to the beginning of the line |
dG |
Delete To End Of Document |
d1G |
To delete the first section of the document |
In addition, you can also add a number in front of the command, expressed delete multiple lines, such as: 2dd
express delete row 2