vim中的替换操作

  在vim中 :s(substitute)命令用于查找并替换字符串。使用方法如下:

:s/<find-this>/<replace-with-this>/<flags>

  例如:

1 :%s/foo/bar/g  # 在全局范围内(%)查找foo并将之替换为bar,所有出现都会被替换(g)
2 :s/foo/bar/g  # 在当前行内查找foo并将之替换为bar,所有出现都会被替换(g)
3 :'<,'>s/foo/bar/g  # 在选区内进行替换,Visual模式下选择区域后输入会自动补全'<,'>

  下面是一些可以加的flag.    for example,  :s/cat/dog/gi  会把cat.Cat() 变成 dog.dog().

  g —global replace: replace every occurrence of the pattern, not just the first one

  c —confirm each substitution: prompt the user before replacing the text

  e —do not show errors if no matches are found

  i —ignore case: make the search case-insensitive

  I —make the search case-sensitive

  最后说一个小tip: 程序员喜欢用foo和bar指代变量名: foo bar -> Fucked Up Beyond All Repair 完全无法修补。

转载于:https://www.cnblogs.com/chester-cs/p/11605656.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值