The VI Editor is a text tool that handles ASCII data. Most Linux distributions already have the VI editor installed by default. VI is the abbreviation for Visual interface vim is the visual interface improved is the enhanced version of the VI,VIM default support code commands are highlighted, which makes the text easier to read. VI There are two kinds of configuration files, one is the global profile/ETC/VIMRC, and the settings for the global profile take effect for all users. The other is the user profile, this profile needs to be manually created by itself, such as Touch ~/.VIMRC, created in the user home directory, and to create it as a hidden file, where the settings are only for the current user itself to take effect.
1, VI of the mode and mode of conversion between
There are three modes, the command mode is also called the edit mode, insert mode (insert mode) and the bottom row mode (last line mode) is also called the terminal mode, the relationship between the modes is as follows:
VI is open by default is the edit mode, editing mode is not able to write any text operations.
(1) Edit mode----> Input mode: You can do the following
Type I:insert directly to enable conversion to input mode at the current cursor position
I: Switch to input mode at the beginning of the line where the cursor is currently located
A:append to convert to input mode after the character where the current cursor is located
A: The line at the end of the current cursor is converted to input mode
O: Implement create a new blank line below the current cursor line and convert to input mode
O: Create a new row above the current cursor and convert to input mode
(2) Input mode-----> Edit mode:
Press the ESC key of the keyboard
(3) Edit mode-----> last line mode
Type:
(4) Last-line mode-----> Edit mode
Press the ESC key continuously twice
2. Operation in edit mode
(1) The cursor jumps:
A) the cursor jumps between characters
H: Left #h jumps to the left # characters
L: Right
J: Next
K: Up
b) The cursor jumps between words
W: The first word of the next word
E: Jumps to the current or next word ending
B: Jump to the beginning of the current or previous word
c) The cursor jumps between sentences
): Next sentence
(: The previous sentence
D) The cursor jumps between paragraphs
}: Next Paragraph
{: Previous paragraph
e) The cursor jumps between the rows:
1g,gg: Jump to the beginning of the line
G: End of line
#G: Nth Row, #表示行数
f) The cursor jumps in the row:
^: first non-whitespace character at the beginning of a line
$: absolute end of line
0: The absolute beginning
(2) Flip screen operation
Ctrl+f: Flipping a screen to the end of a file is equivalent to PageDown operation
CTRL+B: Flip a screen to the file header with respect to the PageUp operation
Ctrl+d: Turn half screen at the end of the file
Ctrl+u: Turn half screen to file header
(3) Copy operation, also called Y (Yank) operation
YY: Indicates that the copy cursor is in the row
#yy: Indicates that the copy includes the line with the cursor and the following # lines, #表示数字
y$: Indicates where the copy cursor is at the end of the line
y^: Indicates where the copy cursor is at the beginning of the line
(4) Paste operation, also called P (paste, put) operation
The entire line is copied:
P: Paste below the line where the cursor is currently located;
P: Paste above the line where the cursor is currently located
The copy is not an entire line:
P: Paste at the back of the character where the cursor is currently located;
P: Paste in front of the character where the current cursor is located;
(5) Delete operation, (X,D)
X: Delete a single character after the cursor
#x: Delete the # characters after the cursor, #表示数字
DW: Delete the word where the cursor is located
DB: Delete the word before the cursor is located
De: Delete the word after the cursor is located
d^: Delete all character words before the cursor
d$: Delete all character words after the cursor is located
DD: Delete the entire row where the cursor is located
#dd: Delete the following lines at the containing cursor #表示数字
(6) Undo operation
If you undo the previous error operation, you can press the U key to undo the previous operation, and the previous 50 operations will be recalled by default. When you feel that the previous undo action also needs to be revoked, press CRTL+U to revoke the revocation.
(7) Find operation, enter/or in edit mode directly, then pick the character you want to find
/keyword: Looks at the end of the file from the current cursor location
Keyword: Find the file header from the current cursor position
N: Next, in the same direction as the Find command
N: The previous one, in the opposite direction of the Find command
3. Operation in input mode
When you type (i,i,a,a,o,o) in edit mode, there will be an-INSERT-word underneath the file, indicating that the input mode is now in input mode and any characters entered into the file will be entered directly into the document.
4, the operation of the last line mode
(1) Save the exit operation
: W Save
: Q exit
: X Save exit
: Wall all saved, general application open multiple pages at the same time
: Qall all exits, general application open multiple pages at the same time
: w! Force Save
: q! Force exit
: wq! Force Save exit
: x! Force Save exit
(2) Delete the operation, in the last line mode operation can support the delimitation
Syntax format start line, end line D
:. Indicates that the current cursor is in the row
: 1 indicates the first row
: # indicates line #, #表示数字
: $ indicates the last line
:% indicates the entire text
: 1, $d delete the first line to the last row
:. $d delete the current cursor until the end of the line
:%d Delete entire text
: 1,+3d Delete the first row and the following three lines, the first row is also included, so delete the four rows
(3) Find operations, find operations and find operations in edit mode, support pattern matching
/keyword: Looks at the end of the file from the current cursor location
Keyword: Find the file header from the current cursor position
N: Next, in the same direction as the Find command
N: The previous one, in the opposite direction of the Find command
(4) Modify the replacement operation, also support pattern matching
Syntax format
: Address delimitation s/Find mode/Replace with content/gi
/Represents a delimiter, can be @, #等特殊容易区别的符合
G Global, I ignore case insensitive
eg
12345678910 |
Delete the beginning of the beginning of the line #: :%[email protected]^ #@@ Delete the beginning of the beginning of the line #及后面紧跟的空白字符; :%[email protected]^ #[[:space:]]*@@ #; :%[email protected]^[[:space:]]@ #&@ :%[email protected]@[email protected] to the beginning of the line in the specified range. #; :1,[email protected]^@ #@g |
5, the Window property definition, in the last line mode: (in the last row mode directly enter the set can see the set of Help command), no represents the reverse meaning
Show line number:
Set Nu
Set Nonu
Auto indent:
Set Autoindent,set AI
Set Noai
Case insensitive
Set ignorecase, set IC
Set Noic
Show matching parentheses
Set Showmatch,set SM
Set NOSM
Syntax coloring
Syntax on
Syntax off
Search highlighting
Set Hlsearch
Set Nohlsearch
You can write the properties of the window definition directly into the vim configuration file.
6, Vim other support
(1) Vim visualization mode
Visual mode
V: Select the character that the cursor is hovering over
V: Select the row where the cursor is hovering, select the entire row
ESC, ESC: Back to edit mode
(2) The same document window is split:
Ctrl+w,s: Horizontal Split Ctrl+w, arrow (up and down), indicating toggle
Enter Q exit in last line mode
Ctrl+w,v: Vertical Split Ctrl+w, arrow (left or right), toggle
Enter Q exit in last line mode
Linux Powerful editor VI