- Three editing modes of vi
- Command mode)
In this mode, you can control the movement of the cursor, delete characters, delete rows, and copy and move a paragraph.
- Insert mode)
Only in this mode can you enter characters
- Last line mode)
In this mode, you can save the file or exit Vi, set the Editor Environment, search for strings, and list the row numbers.
Note: however, vi is generally regarded as two modes, and the last line mode is also included in the command line mode.
- Vi initial experience
Type vi file.txt on the terminal
# Vi file.txt
If you are not familiar with it, you must start directly and press the keyboard for input. If the input is ineffective, you can start to worry about it .. In fact, when you enter the preceding command, it is in the command mode. To switch to the input mode, you only need to press the letter "I". Then you can enter it. to switch to the command mode, you only need to press the "ESC" key.
Save files
In command line mode, click ":" to enter the last line mode, for example:
: W filename (save the file with filename as the file name)
: Wq (save disk and release vi)
: Q! (Force exit vi without saving the disk)
- Command mode function key
- Switch to input mode
After you press "I" to enter the input mode, the input file starts from the current position.
After you press "a" to enter the input mode, the text is entered from the next position where the current cursor is located.
After you press "o" to enter the input mode, a new row is inserted and text is entered from the beginning of the line.
- Switch from input mode to command mode
Press "ESC"
- Move cursor
Vi can be directly moved up, down, left, and right with the cursor on the keyboard, but the regular vi uses lowercase letters h, j, k, and l to control the cursor's left, bottom, Up, And right shifting to one cell.
Press "ctrl" + "B": screen to "back" to move one page
Press "ctrl" + "f": Move the screen to "Front"
Press "ctrl" + "u": Move the screen to "Rear" half page
Press "ctrl" + "d": Move the screen to "Front" half page
Press number 0: Move to the beginning of the article
Move to the end of the article by G
Move to the end of the row where the cursor is located by $
^: Move to the beginning of the row where the cursor is located
Press # l: move the cursor to the # position of the row, such as 5l
- Delete text
Press x: Delete the "Next" character at the cursor position each time.
Press # x: for example, 6x to delete the next six characters in the cursor position
Press X: uppercase X. Each time the cursor is deleted, the first character of the cursor is deleted.
Press # X: Delete the # characters before the cursor
Press dd to delete the row where the cursor is located.
Press # dd: delete from the row where the cursor is located # Row
- Copy
Press yw to copy the character from the cursor position to the end of the word to the buffer zone.
Press # yw: Copy # words to the cache
Press yy: copy the row where the cursor is located to the buffer
Press # yy: Start from the row where the cursor is located and count down # copy the row to the buffer zone
Press p: paste the characters in the buffer zone to the cursor position. All commands related to "y" must work with "p" to complete the copy and paste function.
- Replace
Press r to replace the character at the cursor
Press R: Replace the character at which the cursor is located. Press ESC.
- Undo the last operation
Press u: If you mistakenly execute a command, you can immediately press "u" to return to the previous operation. You can run the "u" command multiple times.
- Change
Press "cw": change the word at the cursor to the ending point.
Press "c # w": for example, "c3w" to change three words
- Jump to the specified row
Press ctrl + g to list the row number of the cursor.
Press # G. For example, "15G" to move the cursor to the first row of the article.
Before using "last line mode", remember to press the "ESC" key to confirm that you are already in "command mode" and then press 「: the colon (:) returns the last line mode 」.
If you want to edit a document, you can directly edit it. If you have document AA, you can use vi AA. [Note: it must be in the directory where AA is located]
If you do not have a document and want to edit it, You can directly edit vi aa]
You can also create a document touch aa before editing vi aa.
The editor has three modes: Command Line Mode 2 last line mode 3 input mode
Press Esc to enter the command line mode and the system default mode.
In input mode, you can press o I a to exit and enter the last line and command line mode.
You can press ctrl + to exit the editor or save the exit document.
Q! [Force exit and do not save] q [exit and do not save] wq [You can add a new one after exiting and saving !]
There are a lot of commands in input mode and command line mode. If you want to know which ones you can talk to me
For example, copy (yy) paste (p) Delete (d) and so on
In linux, how does one edit a file without opening a text editor (vi?
There are many Linux text editors ...... Use whatever you want ...... You can also use echo> to output text to a file.