Linux Martial Arts Cheats (1) Text Editor vi - How to Use and Function Key Table


Linux system editor selection

It is very important to use a text editor to edit the Linux parameter configuration file in the Linux system.

In the Linux world, most configuration files exist in ASCII plain text . So as long as you learn a simple text editing software, it is enough to modify the configuration.

A plain text file means that the files are all recorded by 0 and 1 , and we use the encoding system (ASCII) to convert these 0 and 1 into text we know.

Different Linux distributions have their own additional software tools. If you learn a distribution management tool, it will be embarrassing when you take over different versions.


The birth of the vi editor

There are many editors for editing plain text files under the Linux command line: nano, joe, and vi, etc. The vi editor is the most basic editor and stands out among many editors.

Advantages of vi editor:
1. All Unixes have built-in vi editor by default, and other editors may not come with their own.
2. Many other software editor interfaces call vi
3. Vim has powerful program editing capabilities. It uses font color to judge whether the grammar is correct, and the editing speed is very fast.

vim is an advanced version of vi.
According to vim's official website : Text Editor Vim is a highly configurable text editor that can create and change any type of text very efficiently. With support for hundreds of programming languages ​​and file formats; powerful search and replace functions.


vi editor uses

vi is divided into three modes: "general command mode" (command mode), "edit mode" (insert mode), "command line mode" (command-line mode)

General command mode:
1. The default mode for vi to open files.
2. You can move the cursor by pressing the [Up, Down, Left, and Right] keys. In this mode, you can delete, copy, paste and other operations, but you cannot edit the file content.

Edit mode:
1. In the general command mode, enter the edit mode through any letter of 【i IO oa A r R】.
2. At this time, the words [INSERT] or [REPLACE] will appear in the lower left corner of the interface, indicating that it is currently in edit mode.

Command line mode:
1. In the general command mode, press any key【:/?】to move the cursor to the last line and enter the command line mode.

insert image description here
Note: The general command mode can be switched with the edit mode and the command line mode, but the edit mode cannot be switched with the command line mode


vi editor function key table

Learn the colored logo keys in the function table, and the vi editing operation is simply "happy"! ! ! !

General Command Mode

General command mode
command mode
How to move the cursor
h or left arrow key (←) Move the cursor one character to the left
j or down arrow key (↓) Move the cursor down one character
k or the up arrow key (↑) Move the cursor up one character
l or right arrow key (→) Move the cursor one character to the right
[Ctrl] + [f] Move the screen "down" by one page, which is equivalent to the [Page Down] button
[Ctrl] + [b] Move the screen "up" by one page, which is equivalent to the [Page Up] button
[Ctrl] + [d] Move the screen "down" by half a page
[Ctrl] + [u] Move the screen "up" by half a page
+ Move the cursor to the next line that is not a space character
- Move the cursor to the line above a non-space character
n <space> The n means "number", such as 20. Press the number and then press the space bar, the cursor will move n characters in this line to the right. For example, 20 means that the cursor will move 20 characters behind.
0 or function key [Home] This is the number "0": move to the front character of this line
$ or function key [End] move to the last character of the line
H Move the cursor to the first character of the top line of the screen
M Move the cursor to the first character of the line in the center of the screen
L Move the cursor to the first character of the bottom line of the screen
G Move to the last line of this file
Mr n is a number. Move to line n of this file. For example, 20G will move to the 20th line of this file (can cooperate with: set nu)
gg Move to the first line of this file, which is equivalent to 1G!
n<Enter> n is a number. Move the cursor down n lines
search replace
/word Look under the cursor for a string named word.
?word Look for a character string named word above the cursor.
n This n is the English button. Represents the action of repeating the previous search. Enter /word, press the n button continuously to search for the position of the next word;
N The N is the English button. It is just the opposite of n, and performs the previous search action for "reverse".
:n1,n2s/word1/word2/g n1 and n2 are numbers. Find the string word1 between lines n1 and n2 and replace that string with word2!
:1,$s/word1/word2/g 或 :%s/word1/word2/g Find the word1 string from the first line to the last line and replace that string with word2!
:1,$s/word1/word2/gc 或 :%s/word1/word2/gc Find the word1 string from the first line to the last line and replace that string with word2! And before the replacement, a prompt character is displayed to the user to confirm (confirm) whether it needs to be replaced!
delete, copy, paste
x, X In a line of text, x is to delete a character backward (equivalent to the [del] key), X is to delete a character forward (equivalent to [backspace], which is the backspace key)
nx n is a number, delete n characters consecutively backward. For example, I want to delete 10 characters in a row, "10x".
dd Cut the entire line where the cursor is (commonly used), and use p/P to paste it.
n.d n is a number. Cut the next n lines where the cursor is located. For example, 20dd is to cut 20 lines (commonly used), and it can be pasted with p/P.
d1G Delete all data from the cursor to the first line
dG Delete all data from the cursor to the last line
d$ Delete where the cursor is, to the last character of the line
d0 That is the number 0, delete the position where the cursor is, to the first character of the line
yy Copy the row where the cursor is located
nyy n is a number. Copy the next n lines where the cursor is located, for example, 20yy is to copy 20 lines
y1G Copy all the data from the row where the cursor is located to the first row
yG Copy all the data from the row where the cursor is located to the last row
y0 Copy the character where the cursor is to all the data at the beginning of the line
y$ Copy all the data from the character where the cursor is to the end of the line
p, P p is to paste the copied data on the line below the cursor, and P is to paste the copied data on the line above the cursor! For example, my cursor is currently on line 20, and 10 lines of data have been copied. After pressing p, the 10 rows of data will be pasted after the original 20 rows, that is, the 21 rows will be pasted. But what about pressing P? Then the original 20th line will be pushed to become 30th line.
J Combine the row where the cursor is located with the data of the next row into one row
c Repeatedly delete multiple data, for example, delete 10 rows down, [ 10cj ]
u Undo the previous action.
[Ctrl]+r Redo the last action.
. That's the decimal point! It means to repeat the previous action. If you want to delete repeatedly, paste repeatedly, etc., just press the decimal point "." and that's it!

edit mode

edit mode
insert mode
Enter edit mode for input or substitution
i, I Enter the input mode (Insert mode):
i means "input from the current cursor position", I means "start input at the first non-space character in the current line".
a, A Enter the input mode (Insert mode):
a means "start input from the next character where the current cursor is located", and A means "start input from the last character of the line where the cursor is located". <
the, the Enter the input mode (Insert mode):
This is the case of the English letter o. o is to input a new line at the next line where the current cursor is; O is to input a new line at the previous line where the current cursor is!
r, R Enter Replace mode:
r will only replace the character where the cursor is located once; R will always replace the text where the cursor is located until ESC is pressed;
[Esc] Exit edit mode and return to normal mode

command line mode

command-line mode
command-line mode
Save, leave and other commands on the command line
:w Write the edited data to the hard disk file
:w! If the file attribute is "read-only", the file is forced to be written.
:q leave vi
:q! If you have modified the file and don't want to save it, use ! to force you to leave without saving the file.
:wq Save and leave, if it is :wq!, it is forced to save and leave
ZZ If modified, save the current file and exit! The effect is equivalent to (save and exit)
ZQ Do not save, force quit. The effect is equivalent to :q!.
:w [filename] Save edited data as another file
:r [filename] In the edited data, read the data of another file.
:n1,n2 w [filename] Save the contents of n1 to n2 as filename.
:! command Temporarily leave vi to display the result of executing command in command line mode!
Changes to the vim environment
:set no Display the line number. After setting, the line number of the line will be displayed at the prefix of each line
:set nine Contrary to set nu, to cancel the line number

Guess you like

Origin blog.csdn.net/weixin_43564241/article/details/129506749