Tag: page combination also writes pen question name displays line number moved multiple times
The previous mention of Vim, which is a necessary tool in Linux. No amount of work can be done without it. Early UNIX was used as the system default editor for the VI. You may have doubts, what is the difference between VI and VIM? It is easy to understand that Vim is an upgraded version of VI. Many Linux system administrators are accustomed to VI, that is because they are in contact with Linux when the use of Vi,vim later is more popular. So, it doesn't matter with VI and vim, as long as you can achieve the purpose you want.
In the author's opinion, the biggest difference between VI and VIM is that when editing a text, vi does not display color, and vim displays the color. Display colors are easier for users to edit. There's no difference in other features. So under Linux, the use of VI or VIM depends entirely on your personal interests. I have been using vim from the beginning to learn Linux, so I will always teach you the role of vim.
Three modes of VIM: General mode, edit mode, command mode. This need you to remember, because before the author has just engaged in the work of Linux to interview, a lot of units of the written questions have this knowledge point.
* General mode: When you vim filename to edit a file, it is normal mode to enter the file. In this mode, you can do the following actions: Move the cursor up or down, delete a character, delete a row, copy, paste one line, or multiple lines.
* Edit mode: In general mode, it is not possible to modify a character, only to edit mode. From general mode into edit mode, you can just press a key (I,i,a,a,o,o,r,r). When you enter edit mode, the words "insert or replace" appear on the bottom line of the screen. To return to normal mode from edit mode, simply click the ESC key at the top left of the keyboard.
* Command mode: In normal mode, enter ":" or "/" to enter command mode. In this mode, you can search for a character or a string, or you can save, replace, exit, display line numbers, and so on.
I'll show you how to write a piece of text in a blank document and save it.
Enter VIM Test.txt Direct enter into general mode. Then press the "I" Letter to enter edit mode
You will see the word "INSERT" in the bottom left of the window, stating that you have entered edit mode and can write to the content.
When you finish editing the content, press ESC to exit Edit mode and enter General mode. At this point, the word "INSERT" disappears in the lower left, then press ":" to enter command mode, and finally enter WQ to save and exit vim.
At this point, take a look at the contents of the Test.txt document.
In fact, vim for the full keyboard operation of the editor, so in all modes have a lot of functional keyboard. The following author lists, which I think commonly used will be marked with red, you need more practice, but also not commonly used you need to know.
Move the cursor in general mode |
h or LEFT ARROW key |
The cursor moves one character to the left |
J or DOWN ARROW key |
Move the cursor down one character |
K or UP ARROW key |
Move the cursor up one character |
L or RIGHT ARROW key |
The cursor moves one character to the right |
CTRL + F or PageUp key |
The screen moves forward one page |
CTRL + B or PageDown key |
The screen moves backward one page |
Ctrl + D |
The screen moves forward half a page |
Ctrl + u |
The screen moves back half a page |
+ |
Cursor moves to the next column of non-whitespace |
- |
Cursor moves to the previous column of non-whitespace |
n Spaces (n is number) |
Press the number n and then press a space, the cursor moves to the right n characters, and if the number of characters is less than N, the cursor continues to move from the downstream to the right, up to n |
0 (number 0) or shift+6 |
Move to the beginning of the bank |
Shift+4 |
That ' $ ' moves to the end of the bank. |
H |
Cursor moves to the top row of the current screen |
M |
The cursor moves to the center line of the current screen |
L |
Cursor moves to the bottom row of the current screen |
G |
Cursor moves to the last line of text |
NG (n is number) |
Move to the nth row of the text |
Gg |
Move the first line with the text |
N Enter (n is number) |
Move the cursor down n rows |
Find and Replace in general mode |
/word |
Look for a string named word after the cursor, and when you find the first word, press "n" to continue searching for a |
? word |
Look for a string named word before the cursor, and when you find the first word, press "n" to continue searching for the previous |
: n1,n2s/word1/word2/g |
Find the Word1 string in N1 and N2 and replace it with WORD2, and you can change the "/" to "#" |
: 1, $s/word1/word2/g |
From the first line to the last line, look for word1 and replace it with WORD2 |
: 1, $s/word1/word2/gc |
Plus the role of C is to require user confirmation before replacing |
Delete in general mode , Copy and paste |
X,x |
X to remove one character backwards, X to delete one character forward |
NX (n is numeric) |
Remove n characters backwards |
Dd |
Delete the line where the cursor is located |
NDD (n is numeric) |
Delete the next n rows where the cursor is located |
d1g |
Delete all data from the row to the first row of the cursor |
Dg |
Delete all data from the row to the last row of the cursor |
Yy |
Copy the line where the cursor is located |
Nyy |
Copy down n rows from the line where the cursor is located |
P,p |
P The copied data is pasted from the next line of the cursor, and p is pasted from the cursor line |
y1g |
Copy all data from the row to the first row of the cursor |
YG |
Copy all data from the row to the last row of the cursor |
J |
To combine data from the row of the cursor with the next row |
U |
Restore past operations |
i |
|
i |
insert character at the beginning of the current line |
a |
insert character in current word specifier |
a |
insert character at the end of the current line line |
o |
insert a new line below the current line |
o |
|
r |
Replace the character that the cursor is in, replace only once |
r |
always replace cursor character, until you press ESC |
: W |
Save the edited text |
: w! |
Force Save if Text property is read-only |
: Q |
Exit vim |
: q! |
No edits or edits are not saved exit |
: Wq |
Save, exit |
: e! |
Restore a document to its original state |
Zz |
If the document does not change, then do not store away, if the document has been changed, then the store left, equivalent to: Wq |
: w [filename] |
Save the edited document as FileName |
: R [FileName] |
Reads the contents of the filename document below the line where the current cursor is located |
: Set Nu |
Show line numbers at the beginning of each line |
: Set Nonu |
Cancel line number |
N1,N2 w [filename] |
Save the contents of N1 to N2 as filename for this document |
:! Command |
Temporarily leave Vim to run a Linux command, for example:! Ls/home temporarily lists the files under the/home directory and then prompts you to press ENTER to return to VIM |
Text Editing tools Vim