Home >Computer Tutorials >Computer Knowledge >Several key skills to master the vi editor of Linux system
In Linux systems, the vi editor is a widely used text editor. For system administrators and programmers, it is crucial to master the skills of vi editor. This article will share some commonly used vi editor skills to help readers improve editing efficiency.
To enter the vi editor, just type "vi file name" in the Linux terminal. To edit a specific file directly, use "vi filename" from the command line.
The vi editor is divided into two modes: command mode and insert mode. In command mode, you can execute various commands to manipulate text; in insert mode, you can enter and edit text content. To switch between the two modes, just press the "Esc" key.
In command mode, you can use the following commands to move the cursor:
h:向左移动一个字符 j:向下移动一个字符 k:向上移动一个字符 l:向右移动一个字符 Ctrl + B:向上滚动一页 Ctrl + F:向下滚动一页
In command mode, you can use the following command to delete text:
x:删除光标所在字符 dw:删除光标所在单词 d$:删除光标至行尾的所有字符 d^:删除光标至行首的所有字符 dd:删除光标所在行
In command mode, you can copy and paste text using the following commands:
p:将剪贴板中的内容粘贴到光标后面 P:将剪贴板中的内容粘贴到光标前面 yy:复制光标所在行 yw:复制光标所在单词 y$:复制光标至行尾的所有字符 y^:复制光标至行首的所有字符
In command mode, you can use the following commands to undo and redo operations:
u:撤销最近一次操作 U:撤销所有操作 Ctrl + R:重做最近一次撤销操作
The vi editor can display the line number by setting the line number. In command mode, use the following command to set the display line number:
The vi editor also supports searching and replacing text. In command mode, use the following commands to search and replace text:
搜索文本:输入“/关键词”并按回车键,将光标移动到第一个匹配的字符处。输入“n”可以继续搜索下一个匹配的字符。 替换文本:输入“:%s/旧关键词/新关键词/g”并按回车键,将文件中所有出现的旧关键词替换为新关键词。输入“n”可以继续替换下一个旧关键词。
In command mode, you can use the following command to set text properties:
i:进入插入模式,在光标所在位置插入文本 I:进入插入模式,在行首插入文本 a:进入插入模式,在光标所在位置后面插入文本 A:进入插入模式,在行尾插入文本
vi is a screen editor provided by all UNIX systems, and some are also called multi-mode editors. It provides a window device through which files can be edited, and vim is an upgraded version of vi. It is not only compatible with vi All instructions, and there are some new features in it. The following are some advantages of vim compared to vi
1. Multi-level undo
在vi里,按 u只能撤消上次命令,而在vim里可以无限制的撤消
2. Ease of use
vi只能运行于unix中,而vim不仅可以运行于unix,windows ,mac等多操作平台
3. Syntax highlighting
vim可以用不同的颜色来加亮你的代码。
4. Visual operation
vim不仅可以在终端运行,也可以运行于x window、 mac os、 windows。
5. Full compatibility with vi
vi和vim都是Linux中的编辑器,不同的是vim比较高级,可以视为vi的升级版本。 vi使用于文本编辑,但是vim更适用于coding。 注:coding是编码的意思,decoding是解码的意思
The above is the detailed content of Several key skills to master the vi editor of Linux system. For more information, please follow other related articles on the PHP Chinese website!