Vi commands are quite common, So I studied the Linux vi command and shared it with you here. I hope it will be useful to you. Moving Linux vi on the screen provides three commands about moving the cursor across the screen without scrolling the file itself. They are H, M, and L commands.
Linux vi H command
TheLinux viCommand to move the cursor to the first line of the screen, that is, the first line of the current screen, rather than the first line of the entire file. You can use this command to quickly move the cursor to the top of the screen. If n is added before the H command, move the cursor to the beginning of the n line.
The screen displays the following content:
# Include
Main)
{Int k;
For k = 0; k <3; k ++) add );}
Add)
{Static int x = 0;
X ++;
Printf "x = % d \ n", x );
"Example. c" [New File]
In command mode, enter the 4 H command and move the cursor to the letter f starting with ". It is worth mentioning that the command dH will delete all content from the current row of the cursor to the first line of the displayed screen.
Linux vi M command
This command moves the cursor to the beginning of the line in the middle of the display file. That is, if the current screen is full, it will be moved to the middle line of the screen; if it is not full, it will be moved to the middle line of the lines of the text. This command can be used to quickly move the cursor from any position on the screen to the beginning of the line in the middle of the screen display file. For example, when the above screen is displayed, no matter where the cursor is on the screen), in command mode, after the command M is input, the optical mark will be moved to the letter a in the add line. It is also worth mentioning that using the command dM will delete all content from the current row of the cursor to the middle row of the displayed file on the screen.
Linux vi L command
When the content displayed in the file exceeds one screen, this command moves the cursor to the beginning of the line at the bottom of the screen. When the content displayed in the file is insufficient, this command moves the cursor to the beginning of the last line of the file. This command can be used to quickly and accurately move the cursor to the bottom of the screen or the last line of the file. If n is added before the L command, move the cursor to the beginning of the n line starting from the bottom of the screen. For example, when the above screen is displayed, no matter where the cursor is on the screen), in command mode, after entering the 3L command, the cursor will be moved to the letter x in the row x ++.
It is also worth mentioning that the command dL will delete all content from the current row of the cursor to the bottom line of the screen.
Moving the cursor by words first introduces the concept of "word" in Linux vi. In Vi, "word" has two meanings. A word in a broad sense can be any content between two spaces.
Row 4th in file example. c:
{Int k; it has only two characters, one being {int and the other being k;
Another word in Vi is a word in a narrow sense. In this sense, English words, punctuation marks, and non-letter characters are like! , @, #, $, %, ^, &, *,),-, +, {,}, [,], ~ , |, \, <,>,/, Etc.) are considered as a word. Therefore, the above line contains the words {, int, k, and. In Vi, uppercase commands are generally used to treat words in a broad sense, while lowercase commands are used to treat words in a narrow sense.
After figuring out the meaning of the words in Linux vi, we can introduce the command to move the cursor by words. Linux vi provides three commands for moving the cursor by words:
Linux vi w and W commands
Move the cursor right to the beginning of the next word;
The screen is shown as follows:
Printf "Hello Mr. Huang! \ N ");
Now we can use the w command to move the cursor to the first "" in the narrow sense of the next word:
Printf "Hello Mr. Huang! \ N ");
The following command uses the W command to move the cursor to the header "M" in the broad sense of the next word:
Printf "Hello Mr. Huang! \ N ");
Linux vi e and E commands
If the starting position of the cursor is inside the word, that is, not the end of the word), the command moves the cursor to the end of the word. If the starting position of the cursor is at the end of the word, this command moves the cursor to the end of the next word.
Linux vi B and B
If the cursor is inside the word, that is, not the beginning of the word), the command moves the cursor to the beginning of the word. If the cursor is at the beginning of the word, this command moves the cursor to the beginning of the previous word.
The screen is shown as follows:
Printf "Hello Mr. Huang! \ N ");
Now, run the "B" command. Because the cursor is in the middle of the word, move the cursor to "H" at the beginning of the word:
Printf "Hello Mr. Huang! \ N ");
If you use the B command, it is as follows:
Printf "Hello Mr. Huang! \ N ");
Move the cursor by sentence in Vi. A sentence is defined as comma,), period.), question mark ?) And exclamation point !) Followed by at least two or more spaces or a linefeed character series. Linux vi provides two commands for moving the cursor by sentence:
1. The command moves the cursor to the beginning of the previous sentence.
2. Run this command to move the cursor to the beginning of the next sentence.
Moving the cursor by segment in Linux vi, a segment is defined as a segment that begins and ends with a blank line. Vi provides two commands for moving the cursor by segment:
1. Run this command to move the cursor forward to the beginning of the previous segment;
2. Run this command to move the cursor backward to the beginning of the next segment.
Screen scrolling
On-screen Linux vi commands move the cursor in units of the screen and are often used for scrolling and paging of files. Note that the screen command is not a cursor movement command and cannot be used as a text qualifier to delete commands. You can use screen scrolling commands in command mode and text input mode.
- Linux vi editor concepts
- Linux vi command replacement instructions
- Tips for adding a row number to a linux vi command line
- Practical Tips: linux vi command shortcut key set
- Linux vi command details and usage tips