Introduction to a VIM mode
The following introductory content is from the Wikipedia vim
There are many modes of vim from VI, this unique design is easy to confuse the beginner. Almost all editors have two modes of inserting and executing commands, and most editors use a different approach to vim: the command directory (mouse or keyboard driver), the combination of keys (usually with the control key (CTRL) and the ALT key (ALT)) or the mouse input. Vim and VI, just as the keyboard to switch among these modes. This allows vim to operate without a menu or mouse, and to minimize the operation of key combinations. It can greatly enhance the speed and efficiency of the text entry clerk or programmer.
VIM has 6 basic modes and 5 derivation modes, and here we simply introduce the next 6 basic modes:
In normal mode, the editor commands, such as moving the cursor, deleting text, and so on. This is also the default mode after Vim is started. This is exactly the opposite of what many new users expect (most editor default mode is insert mode).
Vim's powerful editor can come from its normal mode commands. Normal mode commands often require an operator end. For example, the normal mode command dd
deletes the current row, but the first "D" can be followed by another move command instead of the second one d
, such as a "J" key that moves to the next line to delete the current row and the next row. You can also specify the number of commands to repeat, 2dd
(repeat dd
two times), and dj
the effect is the same. Users learn a variety of text between the move/jump commands and other common mode of editing commands, and can be used flexibly combined, can be more efficient than those without the pattern of the editor for text editing.
In normal mode, there are many ways to get into insert mode. The more common way is to press a
(append/append) or i
(insert/insert) key.
- Insertion modes (insert mode)
In this mode, most keystrokes insert text into the text buffer. Most new users want this mode to persist throughout the text editor editing process.
In insert mode, you can press the ESC
key back to normal mode.
- Visual modes (visual mode)
This pattern is similar to normal mode. However, the move command expands the highlighted text area. The highlighted area can be a character, a line, or a piece of text. When a non-moving command is executed, the command is executed to the highlighted area. Vim's "text object" can also be used in this mode as the move command.
- Selection mode (select modes)
This pattern is similar to the behavior of the modeless editor (the way Windows standard text controls are). In this mode, you can use the mouse or cursor keys to highlight the selection of text, but the input of any character, Vim will use this character to replace the selected highlighted text block, and automatically enter the insertion mode.
In command-line mode, you can enter text that will be interpreted and executed. For example, execute commands ( :
keys), search ( /
and ?
keys), or filter commands ( !
keys). After the command is executed, VIM returns to the pattern before the command-line mode, usually in normal mode.
- Ex Mode This is similar to the command-line pattern when using the
:visual
Commands can execute multiple commands at once before leaving the ex mode.
This is commonly used in common mode, insert mode, and command line mode, and this course covers only the three common patterns.
Two. Switching of three common modes
Vim starts into normal mode, in insert mode or command line mode, just press Esc
or Ctrl+[
(this is no use in the VIM course environment) to enter normal mode. In normal mode i
, press (insert) or a
(attach) keys to enter the insert mode, in normal mode press :
enter command line mode. In the command line mode, enter the wq
carriage return and save and exit Vim.
1. Use the VIM command to enter the Vim interface
Vim is appended with the file name that you want to open, or that does not exist (then as a new file). Open the Xfce terminal and enter the following command
$ vim practice_1.txt
Vim editor can also be opened using Vim directly, but no files will be opened.
$ vim
Enter the command line mode and the :e 文件路径
same file can be opened.
2. Cursor movement
After entering Vim, press the i
key to enter insert mode. In this mode you can enter text information below, please enter the following three lines of information:
12345678abcdefghijkshiyanlou.com
Press Esc
Enter normal mode, use the arrow keys in this mode or,,, the h
j
k
l
Key can move the cursor.
Key |
Description |
h |
Left |
l |
Right (lowercase L) |
j |
Under |
k |
On |
w |
Move to the next word |
b |
Move to the previous word |
Try using the arrow keys to move the cursor over these letters in normal mode shiyanlou
.
Iii. Enter insert mode 1. Enter insert mode
Use the following key in normal mode to enter insert mode, and to start typing from the corresponding position
Command |
Description |
i |
Edit at current cursor |
I |
Insert at beginning of line |
A |
Inserting at the end of a row |
a |
Insert an edit after the cursor |
o |
Insert a new row after the current row |
O |
Insert a new row before the current line |
cw |
Replace the character from the position of the cursor to the end of a word |
Try different ways to get into the insert mode from normal mode, add in front of the last line Shiyanlou www.
, Notice that each time you go back to normal mode to switch to insert mode in different ways
Iv. saving a document 1. Save the document in command line mode
Enter the :
command line mode from normal mode, enter w
a carriage return, and save the document. Enter to save the :w 文件名
document as a different file name or save it to another path
V. Exit VIM1. Exit vim in command line mode
Enter :
command line mode from normal mode, enter wq
return, save and exit edit
Here are a few other ways to exit:
Command |
Description |
:q! |
Force quit, do not save |
:q |
Exit |
:wq! |
Force Save and exit |
:w <文件路径> |
Save As |
:saveas 文件路径 |
Save As |
:x |
Save and exit |
:wq |
Save and exit |
2. Exiting vim in normal mode
Normal mode input Shift+zz
can be saved out of vim
Vi. deleting text 1. Delete vim text information in normal mode
Go to normal mode and use the following commands to quickly delete text:
Command |
Description |
x |
Delete the character that the cursor contains |
X |
Delete the previous character of a cursor |
Delete |
Withx |
dd |
Delete entire row |
dw |
Delete a word (not in Chinese) |
d$ OrD |
Delete to end of line |
d^ |
Delete to beginning of line |
dG |
Delete to end of document |
d1G |
Delete to document header |
Getting started with the Vim editor