1.VI is the abbreviation of "Visual interface", its status on Linux as if the edit program on DOS. It can perform many text operations, such as output, delete, find, replace, block operations, and so on, and users can customize them according to their own needs. VI is not a typesetting program, it is not like word or WPS can be the font, format, paragraph and other properties of the orchestration, it is just a text editing program. VI There are no menus, only commands, and commands are numerous.
Vi有三种基本工作模式: 命令模式 文本输入模式 末行模式。
Command-line mode
At any time, no matter what mode the user is in, just click the ESC key to get VI into the command mode; we enter the Launch VI command under the shell environment (prompt $), which is also in this mode when you enter the editor. In this mode, users can enter a variety of legal VI commands for managing their own documents. Any character entered from the keyboard is interpreted as an edit command, and if the input character is a valid VI command, VI completes the corresponding action after accepting the user command. Note, however, that the commands you enter are not displayed on the screen. If the input character is not a legal command of VI, VI will ring the alarm.
Text input mode
Enter the input command in command mode i, attach command A, open command O, modify command C, replace command R or Replace command s can enter the text input mode. In this mode, any characters entered by the user are saved by VI as the contents of the file and displayed on the screen. In the text input process, if you want to return to the command mode, press ESC.
Last-line mode
The last line mode is also known as ex escape mode. In command mode, the user presses the ":" Key to enter the last row mode, at which time VI displays a ":" As a prompt in the final row of the display window (usually the last line of the screen), waiting for the user to enter a command. Most file management commands are executed in this mode (such as writing the contents of the edit buffer to a file medium). After the last command is executed, VI automatically returns to the command mode.
Vim Base operation
Vim is a text editor developed from VI. Code completion, compilation and error jump and other convenient programming features are particularly rich
Enter insert mode:
i: 插入光标前一个字符 I: 插入行首 a: 插入光标后一个字符 A: 插入行未 o: 向下新开一行,插入行首 O: 向上新开一行,插入行首
Enter Command mode:
ESC: Enter command mode from insert mode or last line mode
To move the cursor:
h: 左移 j: 下移 k: 上移 l: 右移M: 光标移动到中间行 L: 光标移动到屏幕最后一行行首 G: 移动到指定行,行号 -Gw: 向后一次移动一个字 b: 向前一次移动一个字{: 按段移动,上移 }: 按段移动,下移Ctr-d: 向下翻半屏 Ctr-u: 向上翻半屏Ctr-f: 向下翻一屏 Ctr-b: 向上翻一屏gg: 光标移动文件开头 G: 光标移动到文件末尾
Delete command:
x: 删除光标后一个字符,相当于 Del X: 删除光标前一个字符,相当于 Backspacedd: 删除光标所在行,n dd 删除指定的行数 D: 删除光标后本行所有内容,包含光标所在字符 d0: 删除光标前本行所有内容,不包含光标所在字符dw: 删除光标开始位置的字,包含光标所在字符
Undo command:
u: 一步一步撤销 Ctr-r: 反撤销
Repeat command:
.: 重复上一次操作的命令
Text line movement:
>>: 文本行右移 <<: 文本行左移
Copy and paste:
yy: 复制当前行,n yy 复制 n 行 p: 在光标所在位置向下新开辟一行,粘贴
Visual mode:
v: 按字符移动,选中文本 V: 按行移动,选中文本可视模式可以配合 d, y, >>, << 实现对文本块的删除,复制,左右移动
Replace operation:
r: 替换当前字符 R: 替换当前行光标后的字符
Find command:
/: str查找n: 下一个N:上一个
Replace command:
Replace all ABC with 123
末行模式下,将光标所在行的abc替换成123:%s/abc/123/g末行模式下,将第一行至第10行之间的abc替换成123:1, 10s/abc/123/g
In Vim, execute the shell command:
末行模式里输入!,后面跟命令
Vim Common commands