2014-11-23 83 views
1

我必须找到这些具有这种图案的话:Vim的正则表达式的查找和替换

File{some numeric characters}= 

示例:File1=File234=File3456=并将其删除。

这是该行:

File1=/media/sda5/ 

我现在已经来替换这一行:

/media/sda5/ 

由于我是新来的vim,所以,如果有人能帮助我

+0

可能重复[如何更改vim编辑器中的字符串?](http://stackoverflow.com/questions/13355809/how-to-change-a-string-in-the-vim-editor) – whoan 2014-11-23 16:45:16

+1

': %s/^ File1 = \(/ media/sda5 \)/ \ 1/g' – 2014-11-23 16:57:17

回答

3

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

:%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 
+0

它为我工作,谢谢。 你可以请建议一些好的vim参考文档。 – NU113R 2014-11-23 17:08:20

+0

[Vim Regular Expressions 101](http://vimregex.com/)是一款经典的游戏。请参阅Vim中的':help pattern'以供参考。 – romainl 2014-11-23 17:57:11