vim:替换指令

在Vim编辑器中,可以使用命令模式进行全文替换。例如:%s/old/new/g 命令会全局替换所有old为new。不加g参数,如:s/old/new,只会替换当前行的第一个匹配项。添加g参数,如:s/old/new/g,则会替换当前行内的所有匹配项。通过指定行号范围,如:#,#s/old/new/g,可以在特定行范围内进行替换。使用%则表示替换整个文件,加上gc会提示是否替换每个匹配项。" 126875651,14822401,Spring MVC 文件上传与下载实战指南,"['前端开发', '后端开发', 'Spring', 'Java', '文件处理']
摘要由CSDN通过智能技术生成

全文替换:
 

在命令模式下:

 

:%s/old/new/g

将全部的old替换成new

:s/old/new

将光标所在行的第一个old替换为new

:s/old/new/g 

将光标所在行的所有old替换为new

 

 参数g就是global,全局替换

 


参考:

 Lesson 4.4: THE SUBSTITUTE COMMAND


        ** Type  :s/old/new/g  to substitute 'new' for 'old'. **

  1. Move the cursor to the line below marked --->.

  2. Type  :s/thee/the <ENTER> .  Note that this command only changes the
     first occurrence of "thee" in the line.

  3. Now type  :s/thee/the/g .  Adding the  g  flag means to substitute
     globally in the line, change all occurrences of "thee" in the line.

---> thee best time to see thee flowers is in thee spring.

  4. To change every occurrence of a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值