When using the vi editor, there are primarily three modes:
-
Normal Mode:
- This is the default mode after opening a file in vi.
- In Normal Mode, you can use various keyboard commands to navigate the cursor, delete text, copy and paste content, and so on.
- For example, using
h,j,k, andlmoves the cursor left, down, up, and right respectively. - Using
dddeletes a line, andywcopies a word.
-
Insert Mode:
- In Insert Mode, you can directly input text to edit the file.
- You enter Insert Mode by pressing
iin Normal Mode, where any input is added directly to the file. - Pressing
Escreturns you to Normal Mode from Insert Mode. - Other variants include pressing
ato enter Insert Mode and start typing after the current cursor position, or pressingoto open a new line below the current line and enter Insert Mode.
-
Ex Mode or Command-Line Mode:
- In Ex Mode, you can enter specific commands to save, exit, search, and replace text.
- You enter Ex Mode by pressing
:in Normal Mode. - For example, typing
:wsaves the file,:qexits the editor,:wqsaves and exits, and:s/old/new/gperforms a global replacement.
By mastering the transitions between and characteristics of these three modes, you can effectively improve efficiency and accuracy when using the vi editor.
2024年8月14日 13:05 回复