【问题标题】:Vim regular expression find and replaceVim 正则表达式查找和替换
【发布时间】:2023-03-23 07:39:02
【问题描述】:

我必须找到具有这种模式的单词:

File{some numeric characters}=  

例如:File1=File234=File3456= 并删除它们。

这是行:

File1=/media/sda5/  

现在我必须将这一行替换为:

/media/sda5/  

由于我是vim新手,所以如果有人可以帮助我

【问题讨论】:

标签: linux vim


【解决方案1】:

这个命令应该做你想做的:

:%s/File\d\+=//g

:%s/         perform substitution on each line in the buffer
File\d\+=    matches 'File' followed by one or more digits until the first '='
//           deletes the matched text
g            do that on every match on the line

【讨论】:

  • 它对我有用,谢谢。您能否推荐一些好的 vim 参考文档。
  • Vim Regular Expressions 101 是经典之作。请参阅 Vim 中的 :help pattern 以获得真正的参考。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-25
  • 2011-06-16
  • 1970-01-01
  • 2017-01-28
  • 2015-01-11
  • 2012-12-02
  • 1970-01-01
相关资源
最近更新 更多