码迷,mamicode.com
首页 > 系统相关 > 详细

vim中的替换操作

时间:2019-09-29 09:25:35      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:arch   each   bar   使用方法   替换字符串   beyond   rom   pattern   范围   

  在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 完全无法修补。

vim中的替换操作

标签:arch   each   bar   使用方法   替换字符串   beyond   rom   pattern   范围   

原文地址:https://www.cnblogs.com/chester-cs/p/11605656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!