Home > Computer Tutorials > Computer Knowledge > Several key skills to master the vi editor of Linux system

Several key skills to master the vi editor of Linux system

WBOY
Release: 2024-02-29 08:37:46
forward
871 people have browsed it

精通Linux 系统vi编辑器的几个关键技巧

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.

Enter vi editor

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.

Switching between command mode and insert mode

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.

Move cursor

In command mode, you can use the following commands to move the cursor:

h:向左移动一个字符
j:向下移动一个字符
k:向上移动一个字符
l:向右移动一个字符
Ctrl + B:向上滚动一页
Ctrl + F:向下滚动一页
Copy after login

Delete text

In command mode, you can use the following command to delete text:

x:删除光标所在字符
dw:删除光标所在单词
d$:删除光标至行尾的所有字符
d^:删除光标至行首的所有字符
dd:删除光标所在行
Copy after login

Copy and paste text

In command mode, you can copy and paste text using the following commands:

p:将剪贴板中的内容粘贴到光标后面
P:将剪贴板中的内容粘贴到光标前面
yy:复制光标所在行
yw:复制光标所在单词
y$:复制光标至行尾的所有字符
y^:复制光标至行首的所有字符
Copy after login

Undo and redo operations

In command mode, you can use the following commands to undo and redo operations:

u:撤销最近一次操作
U:撤销所有操作
Ctrl + R:重做最近一次撤销操作
Copy after login

Display line number

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:

  • Display the line number in the current line: enter ":set number" and press the Enter key
  • Display line numbers on all lines: Enter ":set number!" and press Enter

Search and replace text

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”可以继续替换下一个旧关键词。
Copy after login

Set text properties

In command mode, you can use the following command to set text properties:

i:进入插入模式,在光标所在位置插入文本
I:进入插入模式,在行首插入文本
a:进入插入模式,在光标所在位置后面插入文本
A:进入插入模式,在行尾插入文本
Copy after login

vim is the upgraded version of vi

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里可以无限制的撤消
Copy after login

2. Ease of use

vi只能运行于unix中,而vim不仅可以运行于unix,windows ,mac等多操作平台
Copy after login

3. Syntax highlighting

vim可以用不同的颜色来加亮你的代码。
Copy after login

4. Visual operation

vim不仅可以在终端运行,也可以运行于x window、 mac os、 windows。
Copy after login

5. Full compatibility with vi

vi和vim都是Linux中的编辑器,不同的是vim比较高级,可以视为vi的升级版本。
vi使用于文本编辑,但是vim更适用于coding。
注:coding是编码的意思,decoding是解码的意思
Copy after login

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!

Related labels:
source:mryunwei.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template