What is Vim?
Vim is a text editor for Linux. It developed from VI and made many improvements on the basis of VI.
The server of a large website is usually Linux system without graphical interface. When debugging or remote processing is required, you can only call up the terminal (terminal window), and then call up the Vim editor by using the command vim index. HTML to make changes.
Vim shortcut key training tool —-VimTutor VimTutor is a Vim built-in application for beginners to quickly start Vim, directly in the Vim command line, click VimTutor, press Enter to enter the practice.
Vim model
The basic pattern
Normal mode
In normal mode, editor commands are used, such as moving the cursor, deleting text, and so on. This is also the default mode when Vim starts. Vim’s powerful editing power comes from its normal mode commands. Normal mode commands often require an operator ending. For example, the normal mode command “dd” deletes the current line, but the first “D” can be followed by another move command to replace the second “D”, such as the move to the next line of the “J” key to delete the current line and the next line. You can also specify the number of times the command is repeated. “2dd” (repeat “dd” twice) has the same effect as “DJ”.
In normal mode, there are many ways to enter insert mode. A common way to do this is to press “A” (append/Append) or “I” (Insert/insert).
Insert mode
In this mode, most keys insert text into the text buffer. Most new users want the text editor to keep this mode throughout the editing process. In insert mode, you can press ESC to return to normal mode.
Visual model
This pattern is similar to the normal pattern. But the move command enlarges the highlighted text area. The highlighted area can be a character, line, or block of text. When a non-move command is executed, the command is executed on this highlighted area. Vim’s “text object” can also be used in this mode as well as the move command.
Select the schema
This pattern is similar to the behavior of a schemaless editor. In this mode, selected text can be highlighted with the mouse or cursor keys, but if you type any character, Vim replaces the selected highlighted text block with that character and automatically enters insert mode.
Command line mode
The command line mode allows you to enter text that will be interpreted and executed. For example, run the command (: key) to search for (/ and? Key) or filter commands (“!” Key). After the command is executed, Vim returns to the mode before the command line mode, usually normal mode.
The Ex model
This is similar to the command line mode in that multiple commands can be executed at once before exiting Ex mode using the :visual command.
The derived model
The operator waits for mode
This derived mode refers to the normal mode in which Vim waits for an “action” to complete an action command after executing it. Vim also supports the use of “text objects” as actions in operator wait mode, including “AW” a word, “as” a sentence, “AP” a paragraph, and so on. For example, in normal mode “d2as” deletes the current and next sentences. In visual mode “apU” capitalizes all letters in the current paragraph.
Insert normal mode
This mode is entered when CTRL + O is pressed in Insert mode. After executing a command, Vim returns to insert mode
Insert visual mode
This mode starts when CTRL + O is pressed in insert mode and a visual selection begins. When the visual area is selected cancel, Vim returns to insert mode.
Insert select mode
Usually this mode is entered by mouse drag and drop in insert mode or shift. When the selection area is removed, Vim returns to insert mode.
Replace mode
This is a special insert mode in which the same operation can be done as in insert mode, but each character entered overwrites characters already in the text buffer. Press “R” to enter in normal mode.
other
Evim (Easy Vim)
Evim (Easy Vim) is a special GUI mode designed to behave as much as possible like the “modelless” editor. The editor automatically enters and stays in insert mode, and the user can only manipulate text through menus, mouse and keyboard controls. You can enter evim or vim -y on the cli. In Windows, you can also click the Evim (Easy Vim) icon on the desktop.
Vim common commands
Edit the document in Insert/Normal mode
The default mode is Normal after vim is enabled. Normal mode allows you to move your cursor, followed by some simple commands in Normal mode. In Normal mode, almost all keys are function keys.
I — Insert mode. This mode allows you to type text like notepad. If you have finished typing, press ESC to return to Normal mode.
X — Deletes the character at the current cursor position
: w – inventory
:q — Exit. You can use :wq to do both
Dd — Cut the current row
P – paste
HJKL — The effect is the same as ←↓↑→, used to move the cursor
:help
Learn more commands
There are other insertion modes to choose from besides I
A — Insert after the cursor
O — Inserts a new row after the current one
O — Inserts a new row before the current one
Some commands to move the cursor quickly
0 — the number zero, to the wardrobe
^ — to the first non-null character on the line
$– to the end of the line
G_ — to the last non-null character at the end of the line
/pa — Search the string pa, press n to find the next one
Instructions on files
:e <path/to/file> — Opens a file
:saveas <path/to/file> — saveas
:q! Exit without saving: QA! You can exit all files under editing
:bn :bp — When you have a lot of files open, use this to switch to the next/previous one
Other instructions
U – undo
CTRL + r, redo
Learn technical commands
Vim repeats his method
— Decimal point, repeat last command
N
Here is a special example
100imeow[ESC] – Write down 100 ‘meow’
Repeat the previous command and write 100 more “meow”
- — Repeat the command 3 times to write 3 “meow” instead of 300
Move cursor command into class
NG — move to line NTH, :N also works
Gg — go to the first line
G — go to the last row
W — to the beginning of the next word
E — to the end of the next word
% – When the cursor is over a parenthesis, it can be moved to a corresponding parenthesis
And # — move to the next/previous word where the cursor is
In fact, these commands can be combined in the following format:
For a simple example
0y — 0 and — 0 and — 0 and are positions, and y is the instruction, which means to copy from the head of the line to the last character on the line.
In addition to y, there are several commands that can do this, such as
D – delete
GU/gU — Changes to upper/lower case
V — Visual selection
Learning superpowers
More advanced cursor movement
Fa/ Fa — Moves to the previous/next a character, and a can be replaced with other characters
T,/ T, — moves to the character after/before the comma, and the comma can be replaced with other characters
3FA — to the third a character
Dt “– delete everything before encountering
Area selection
The command format for area selection is a and I
Use a simple example to distinguish a from I
Suppose you have a string — [123((abcd))], and your cursor is over B
Vi) — will choose ABCD
Va) — will choose (ABCD)
V2i – will select (ABCD)
V2a) — will select ((abcd))
auto-complete
To use autocomplete, type the beginning of a word in Insert mode and press CTRL + P or + N
The macro
Qa – Start recording macros and record your actions in A
@a — replay the macro you recorded in A
@@ — The latest macro of replay
This article is from {open source factory}