


Usage of global replacement command in vim editor
The syntax is:[addr]s/source string/destination string/[option]
The global replacement command is::%s/source string/destination string/g
[addr] indicates the search range, and when omitted, it indicates the current line.
For example: "1,20": indicates from line 1 to line 20;
"%": indicates the entire file, the same as "1,$";
".,$": from the current line to the end of the file;
s: represents the replacement operation
[option]: represents the operation type
For example: g represents global replacement;
c means to confirm
p means that the substitution results are displayed line by line (Ctrl + L restores the screen);
When option is omitted, only the first matching string in each line is Replacement;
If special characters appear in the source string and destination string, they need to be escaped with "\"
The following are some examples:
#Replace That or Replace this with This or that
:%s/\(That\) or \(this\)/\u\2 or \l\1/
—-
#Replace child at the end of the sentence with children
:%s/child\([ ,.;!:?]\)/children\1/g
—-
#Replace mgi/r/abox with mgi/r/asquare
:g/mg\([ira]\)box/s//mg//my\1square/g <= > :g/mg[ira]box/s/box/square/g
—-
#Replace multiple spaces into one space
:%s/ */ /g
—-
#Use spaces to replace one or more spaces after a period or colon
:%s/\([:.]\) * /\1 /g
—-
#Delete all blank lines
:g/^$/d
—-
# Delete all blank lines and blank lines
:g/^[ ][ ]*$/d
—-
#Insert two blanks at the beginning of each line
:%s/^/> /
—-
#Add at the end of the next 6 lines.
:.,5/$ /./
—-
#Reverse the line order of the file
:g/.*/m0O <=> :g/^/m0O
—--
#Find the starting line that is not a number and move it to the end of the file
:g!/^[0-9]/m$ <=> g/^[^0-9]/m$
—-
#Copy 10 words from lines 12 to 17 of the file and put them at the end of the current file
:1,10g/^/12,17t$
~~~~The role of the number of repetitions
——-
#Place the second line below the chapter start line The content is written in the begin file
:g/^chapter/.+2w>>begin
—-
:/^part2/,/^part3/ g/^chapter/.+2w>>begin
—-
:/^part2/,/^part3/g/^chapter/.+2w>>begin|+ t$
The above is the detailed content of Usage of global replacement command in vim editor. For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The sudo command allows users to run commands in elevated privilege mode without switching to superuser mode. This article will introduce how to simulate functions similar to sudo commands in Windows systems. What is the Shudao Command? Sudo (short for "superuser do") is a command-line tool that allows users of Unix-based operating systems such as Linux and MacOS to execute commands with elevated privileges typically held by administrators. Running SUDO commands in Windows 11/10 However, with the launch of the latest Windows 11 Insider preview version, Windows users can now experience this feature. This new feature enables users to

This article will introduce readers to how to use the command prompt (CommandPrompt) to find the physical address (MAC address) of the network adapter in Win11 system. A MAC address is a unique identifier for a network interface card (NIC), which plays an important role in network communications. Through the command prompt, users can easily obtain the MAC address information of all network adapters on the current computer, which is very helpful for network troubleshooting, configuring network settings and other tasks. Method 1: Use "Command Prompt" 1. Press the [Win+X] key combination, or [right-click] click the [Windows logo] on the taskbar, and in the menu item that opens, select [Run]; 2. Run the window , enter the [cmd] command, and then

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,

1. Overview The sar command displays system usage reports through data collected from system activities. These reports are made up of different sections, each containing the type of data and when the data was collected. The default mode of the sar command displays the CPU usage at different time increments for various resources accessing the CPU (such as users, systems, I/O schedulers, etc.). Additionally, it displays the percentage of idle CPU for a given time period. The average value for each data point is listed at the bottom of the report. sar reports collected data every 10 minutes by default, but you can use various options to filter and adjust these reports. Similar to the uptime command, the sar command can also help you monitor the CPU load. Through sar, you can understand the occurrence of excessive load

In Win11 system, you can enable or disable Hyper-V enhanced session mode through commands. This article will introduce how to use commands to operate and help users better manage and control Hyper-V functions in the system. Hyper-V is a virtualization technology provided by Microsoft. It is built into Windows Server and Windows 10 and 11 (except Home Edition), allowing users to run virtual operating systems in Windows systems. Although virtual machines are isolated from the host operating system, they can still use the host's resources, such as sound cards and storage devices, through settings. One of the key settings is to enable Enhanced Session Mode. Enhanced session mode is Hyper

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.

What is the correct way to restart a service in Linux? When using a Linux system, we often encounter situations where we need to restart a certain service, but sometimes we may encounter some problems when restarting the service, such as the service not actually stopping or starting. Therefore, it is very important to master the correct way to restart services. In Linux, you can usually use the systemctl command to manage system services. The systemctl command is part of the systemd system manager

WPS is a commonly used office software suite, and the WPS table function is widely used for data processing and calculations. In the WPS table, there is a very useful function, the DATEDIF function, which is used to calculate the time difference between two dates. The DATEDIF function is the abbreviation of the English word DateDifference. Its syntax is as follows: DATEDIF(start_date,end_date,unit) where start_date represents the starting date.
