Home  >  Article  >  Operation and Maintenance  >  Three modes of vi editor

Three modes of vi editor

尚
Original
2019-07-23 10:19:0720888browse

Three modes of vi editor

The vi editor is the original editor for Unix systems. It uses console graphics mode to simulate a text editing window, allowing you to view lines in a file, move within the file, insert, edit, and replace text.

vi is divided into three modes: command mode, edit mode, and last line mode.

(1) Command mode

The command mode is the initial mode of vi. Type "$vi file name" under normal permissions or type "# vi file name" under temporary root user (for example: root@XXX-virtualBox:/ect# vi vsftpd.conf) to initially enter the vi command mode. Press esc in edit mode to enter command mode. Many writings on the Internet say that pressing esc in the last line mode can enter the command mode. After my computer enters the last line mode, almost all the keys are input. When typing esc, it will display "^[" without returning to the command mode. So if you are in the same situation as me and enter the last line mode and cannot switch modes, don't press the Enter key randomly.

In command mode:

ZZ: Exit vi

h or <-Left key: Move one character left

j or Down key: Down Move one line

k or up key: move up one line

l or right key: move one character to the right

pageDown (or ctrl F): scroll down one screen

pageUp (or ctrl B): Scroll up one screen

G: Move to the last line in the buffer

num G: Move to the num line in the buffer

gg: Move the first line of the buffer

x: Delete the character at the current cursor position

dd: Delete the line at the current cursor

dw: Delete the current cursor The word at the current position

d$: Delete the content from the current cursor position to the end of the line

J: Delete the newline character at the end of the line where the current cursor is (splicing lines)

u: Undo the previous editing command

a: Append data after the current cursor

A: Append data at the end of the line where the current cursor is

r char: Use char Replace a single character at the current cursor position

R text: Use text to overwrite the data at the current cursor position until the ESC key is pressed

A command that is easy to press by mistake: qq: lower left corner The mark "recording@" will appear. This is a powerful feature of vim. It can record a macro and press q to stop macro recording.

(2) Edit mode

Enter after pressing [i, I, o, O, a, A, r, R] and other letters in the command mode Edit mode. When pressing the above letters, the words [--INSERT-- or --INSERT--] may appear in the lower left corner of the screen, allowing text data input. The meaning of each key is as follows:

a: Start inserting

after the cursor A: Start inserting

at the end of the line i: Start inserting

# from before the cursor position ##I: Insert from the first non-blank character in the column where the cursor is located

o: Add a new column under the cursor and enter input mode

O: Insert where the cursor is Add a new column above the column and enter the input mode

ESC: Return to the command mode

(3) Last line mode

Many people on the Internet say that in the command mode Entering [:] will enter the last line mode. My computer: has no effect. You need to be in uppercase mode (press the CapsLock key) and then press the q key. The last line will appear:. Note that you cannot switch back to other modes at this time (if you can, please leave a message and I will modify it, thank you). You can enter the command

:q after: If there is unmodified buffer data, exit.

:q! Cancel all modifications to the buffer data and exit [Exit without saving]

:w filename Save the file to another file

:wq Save the buffer data to the file and exit

:sp up and down split screen

:vsp left and right split screen

ctrl w w switch screen

Some information In the write command mode, enter [/] to enter the last line mode, which is different from the command of:. After /, you can enter the search content or some commands. If an incorrect command is entered after /, it will automatically return to command mode.

Related recommendations: "

Linux Tutorial"

The above is the detailed content of Three modes of vi editor. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn