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:向下滚动一页
Delete text
In command mode, you can use the following command to delete text:
x:删除光标所在字符 dw:删除光标所在单词 d$:删除光标至行尾的所有字符 d^:删除光标至行首的所有字符 dd:删除光标所在行
Copy and paste text
In command mode, you can copy and paste text using the following commands:
p:将剪贴板中的内容粘贴到光标后面 P:将剪贴板中的内容粘贴到光标前面 yy:复制光标所在行 yw:复制光标所在单词 y$:复制光标至行尾的所有字符 y^:复制光标至行首的所有字符
Undo and redo operations
In command mode, you can use the following commands to undo and redo operations:
u:撤销最近一次操作 U:撤销所有操作 Ctrl + R:重做最近一次撤销操作
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”可以继续替换下一个旧关键词。
Set text properties
In command mode, you can use the following command to set text properties:
i:进入插入模式,在光标所在位置插入文本 I:进入插入模式,在行首插入文本 a:进入插入模式,在光标所在位置后面插入文本 A:进入插入模式,在行尾插入文本
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里可以无限制的撤消
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!

Do you have trouble downloading or sending attachments in Outlook 365? Sometimes, Outlook doesn’t show them for some unknown reason, so you are unable to see them. In this post on php.cn Website, we collect some use tips for attachments not showing.

When V Rising players try to join a server that is close to or already full, they may encounter the “V Rising connection timed out” issue. If you are one of them, you can refer to this post from php.cn to get solutions. Now, keep on your reading.

Windows supplies real-time protection via Windows Security. But this feature may prevent you from doing something it thinks are dangerous. In this situation, you may want to temporarily turn on real-time protection. This php.cn post will show you how

Microsoft has started working on next year’s Windows updates very early. Recent rumors state that the next update in 2024 might be Windows 11 24H2 rather than Windows 12. Everything is uncertain now. php.cn will now take you to see some related infor

The error 0x80030001 often happens when you are attempting to copy files. The error code will be accompanied by a message that tells “unable to perform requested operation”. If you are struggling with this error, you can read this article on php.cn W

On February 13, 2024, Microsoft released KB5034765 (OS builds 22621.3155 and 22631.3155) for Windows 11 22H2 and Windows 11 23H2. This security update brings you many new improvements and bug fixes. You can learn how to download and install Windows 1

Device Manager is widely used when you need to fix some computer issues. You can check the problematic devices and decide to uninstall or update device drivers. Besides, you can also set Power Management settings in Device Manager. However, you may f

When Backup and Restore (Windows Backup) fails to work, you can choose to reset it to default. How to restore Windows Backup to default in Windows 11/10? php.cn will guide you to easily do this thing in 2 ways and let’s go to see them.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.