search
HomeOperation and MaintenanceLinux Operation and MaintenanceUsage of global replacement command in vim editor
Usage of global replacement command in vim editorAug 22, 2017 pm 02:11 PM
Orderusageeditor

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!

Statement
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
如何解决 Windows 11 中的文件名或扩展名过长的问题?如何解决 Windows 11 中的文件名或扩展名过长的问题?Apr 22, 2023 pm 04:37 PM

您在传输文件时是否遇到过任何问题,并且禁止您这样做?好吧,许多Windows用户最近报告说,他们在将文件复制并粘贴到文件夹中时遇到了问题,其中抛出了一个错误,提示“目标文件夹的文件名太长”。此外,其他一些Windows用户在打开任何文件时表示失望,并说“文件名或扩展名太长”,他们无法打开文件。这不允许他们将文件传输到任何其他文件夹,这让用户感到失望。在分析问题时,我们提出了一系列解决方案,可能有助于缓解问题,用户可以轻松传输文件。如果您也遇到类似情况,请参阅此帖子以了解更多信息。来源:https

如何在Windows 11、10中关闭Windows Defender智能屏幕?如何在Windows 11、10中关闭Windows Defender智能屏幕?Apr 26, 2023 am 11:46 AM

许多Windows用户最近报告说,当WindowsDefenderSmartScreen警告用户不要启动MicrosoftWindows无法识别的应用程序时,他们感到恼火,他们每次都必须单击“仍然运行”选项。Windows用户不确定他们目前可以做些什么来避免或禁用它。在研究了这个问题后,我们发现系统上的WindowsDefender功能可以通过设置应用程序或本地组策略编辑器或通过调整注册表文件来禁用。通过这样做,用户将不再需要面对防守者SmartScreen。如果您的系统也遇到

15 款 Python 编辑器/ IDE 详细攻略,总有一款适合你!15 款 Python 编辑器/ IDE 详细攻略,总有一款适合你!Aug 09, 2023 pm 05:44 PM

写 Python 代码最好的方式莫过于使用集成开发环境(IDE)了。它们不仅能使你的工作更加简单、更具逻辑性,还能够提升编程体验和效率。每个人都知道这一点。而问题在于,如何从众多选项中选择最好的 Python 开发环境。

修复 Windows 11/10 登录选项被禁用的问题修复 Windows 11/10 登录选项被禁用的问题May 07, 2023 pm 01:10 PM

许多Windows用户都遇到过由于登录尝试失败或多次关闭系统而无法登录Windows11/10系统的问题。用户很沮丧,因为他们对此无能为力。用户可能忘记了登录系统的PIN码,或者在使用或安装软件时出现卡顿,系统可能被多次强制关闭。因此,我们制定了一份最好的可用解决方案列表,这些解决方案无疑将帮助消费者解决这个问题。要了解更多信息,请继续阅读本文。注意:在此之前,请确保您拥有系统的管理员凭据和Microsoft帐户密码以重置PIN。如果没有,请等待一个小时左右,然后尝试使用正确的PIN

强烈推荐十个 Python IDE 和代码编辑器!强烈推荐十个 Python IDE 和代码编辑器!Apr 19, 2023 pm 07:04 PM

Python非常易学,强大的编程语言。Python包括高效高级的数据结构,提供简单且高效的面向对象编程。Python的学习过程少不了IDE或者代码编辑器,或者集成的开发编辑器(IDE)。这些Python开发工具帮助开发者加快使用Python开发的速度,提高效率。高效的代码编辑器或者IDE应该会提供插件,工具等能帮助开发者高效开发的特性。1.VimVim可以说是Python最好的IDE。Vim是高级文本编辑器,旨在提供实际的Unix编辑器‘Vi’功能,支持更多更完善的特

如何使用 ClipChamp:免费的 Windows 11 视频编辑器如何使用 ClipChamp:免费的 Windows 11 视频编辑器Apr 20, 2023 am 11:55 AM

还记得Windows7上的WindowsMovieMaker吗?自从停止WindowsMovieMaker以来,微软还没有推出任何真正的电影制作者。另一方面,他们尝试用一个小巧轻便的内置视频编辑器来改造照片应用程序。很长一段时间后,微软推出了Clipchamp,这是一款适用于所有Windows11设备的更好的视频处理器。在本文中,我们将深入探讨如何从Windows11设备上的Clipchamp应用程序中获取所有内容。如何使用Clipchamp–详细教程我们提供

如何在 Windows 11 和 10 上使用 Clipchamp 视频编辑器如何在 Windows 11 和 10 上使用 Clipchamp 视频编辑器Apr 17, 2023 pm 07:55 PM

如何在Windows上安装和使用ClipchampClipchamp应用程序尚未预装在Windows上,但这是未来的计划。同时,您需要先下载并安装Clipchamp。要在Windows11和Windows10上安装和使用Clipchamp:从MicrosoftStore下载并安装Clipchamp。安装后,在开始菜单中搜索Clipchamp以启动它。在Clipchamp窗口中,您需要使用您的Microsoft或Google帐户登录,或者使用您自己的个人电子邮

Golang编辑器推荐:五个适合开发的选择Golang编辑器推荐:五个适合开发的选择Jan 19, 2024 am 09:00 AM

随着Golang的流行和普及,越来越多的开发者开始使用这门编程语言。然而,和其他流行的编程语言一样,Golang的开发需要选择一款适合的编辑器来提高开发效率。在本文中,我们将介绍五个适合Golang开发的编辑器。VisualStudioCodeVisualStudioCode(简称VSCode)是微软开发的一款免费的跨平台编辑器。它是基于Elect

See all articles

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)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

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.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),