Table of Contents
Enter vi editor
Switching between command mode and insert mode
Move cursor
Delete text
Copy and paste text
Undo and redo operations
Display line number
Search and replace text
Set text properties
vim is the upgraded version of vi
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

Feb 29, 2024 am 08:37 AM
model editor vi

精通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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does WeChat's Do Not Disturb mode do? What does WeChat's Do Not Disturb mode do? Feb 23, 2024 pm 10:48 PM

What does WeChat Do Not Disturb mode mean? Nowadays, with the popularity of smartphones and the rapid development of mobile Internet, social media platforms have become an indispensable part of people's daily lives. WeChat is one of the most popular social media platforms in China, and almost everyone has a WeChat account. We can communicate with friends, family, and colleagues in real time through WeChat, share moments in our lives, and understand each other’s current situation. However, in this era, we are also inevitably faced with the problems of information overload and privacy leakage, especially for those who need to focus or

What is sleep mode used for on iPhone? What is sleep mode used for on iPhone? Nov 04, 2023 am 11:13 AM

iOS devices have long been able to track your sleep patterns and more using the Health app. But isn’t it annoying when you’re disturbed by notifications while you’re sleeping? These notifications may be irrelevant and therefore disrupt your sleep patterns in the process. While Do Not Disturb mode is a great way to avoid distractions while sleeping, it can cause you to miss important calls and messages you receive during the night. Thankfully, this is where sleep mode comes in. Let’s learn more about it and how to use it on iPhone. What role does sleep mode play on the iPhone? Sleep mode is a dedicated focus mode in iOS that is automatically activated based on your sleep schedule in the "Health" App. It helps you set an alarm and then

Detailed guide to 15 Python editors/IDEs, there is always one that suits you! Detailed guide to 15 Python editors/IDEs, there is always one that suits you! Aug 09, 2023 pm 05:44 PM

There is no better way to write Python code than using an integrated development environment (IDE). Not only can they make your work simpler and more logical, they can also improve programming experience and efficiency. Everyone knows this. The question is, how to choose the best Python development environment among the many options.

Essential software for C language programming: five good helpers recommended for beginners Essential software for C language programming: five good helpers recommended for beginners Feb 20, 2024 pm 08:18 PM

C language is a basic and important programming language. For beginners, it is very important to choose appropriate programming software. There are many different C programming software options on the market, but for beginners, it can be a bit confusing to choose which one is right for you. This article will recommend five C language programming software to beginners to help them get started quickly and improve their programming skills. Dev-C++Dev-C++ is a free and open source integrated development environment (IDE), especially suitable for beginners. It is simple and easy to use, integrating editor,

Do Not Disturb Mode Not Working in iPhone: Fix Do Not Disturb Mode Not Working in iPhone: Fix Apr 24, 2024 pm 04:50 PM

Even answering calls in Do Not Disturb mode can be a very annoying experience. As the name suggests, Do Not Disturb mode turns off all incoming call notifications and alerts from emails, messages, etc. You can follow these solution sets to fix it. Fix 1 – Enable Focus Mode Enable focus mode on your phone. Step 1 – Swipe down from the top to access Control Center. Step 2 – Next, enable “Focus Mode” on your phone. Focus Mode enables Do Not Disturb mode on your phone. It won't cause any incoming call alerts to appear on your phone. Fix 2 – Change Focus Mode Settings If there are some issues in the focus mode settings, you should fix them. Step 1 – Open your iPhone settings window. Step 2 – Next, turn on the Focus mode settings

Fix the issue where Windows 11/10 login options are disabled Fix the issue where Windows 11/10 login options are disabled May 07, 2023 pm 01:10 PM

Many Windows users have encountered the problem of being unable to log in to Windows 11/10 systems due to failed login attempts or multiple system shutdowns. Users are frustrated because there is nothing they can do about it. Users may forget their PIN code to log into the system, or experience lags when using or installing software, and the system may be forced to shut down multiple times. Therefore, we have compiled a list of the best available solutions that will undoubtedly help consumers solve this problem. To learn more, continue reading this article. Note: Before doing this, make sure you have your system's administrator credentials and Microsoft account password to reset your PIN. If not, wait an hour or so and try with the correct PIN

How to solve the problem that linux vi does not display the cursor How to solve the problem that linux vi does not display the cursor May 30, 2023 pm 10:34 PM

Solution to Linuxvi not displaying the cursor: 1. Log in to the Linux system and enter the terminal; 2. Display the cursor by executing the "echo-e"\033[?25h"" method. The Linux terminal cursor disappears problem. When I was writing a script in vim today, I suddenly found that the cursor disappeared. This was very uncomfortable. I didn’t know where the editing position was. At first I was looking for vim configuration issues, but later I found that the terminal cursor also disappeared. Only then did we know that the terminal's cursor and vim's cursor are related, so we only need to get out the terminal's cursor. Hide the cursor echo-e"\033[?25l"Show the cursor echo-e&quo

Introduction to Go language development tools: a list of essential tools Introduction to Go language development tools: a list of essential tools Mar 29, 2024 pm 01:06 PM

Title: Introduction to Go language development tools: List of essential tools In the development process of Go language, using appropriate development tools can improve development efficiency and code quality. This article will introduce several essential tools commonly used in Go language development, and attach specific code examples to allow readers to understand their usage and functions more intuitively. 1.VisualStudioCodeVisualStudioCode is a lightweight and powerful cross-platform development tool with rich plug-ins and functions.

See all articles