如何在 vi 搜索中包含正斜杠 &代替 [英] How to include forward slash in vi search & replace

查看:81
本文介绍了如何在 vi 搜索中包含正斜杠 &代替的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含字符串 usrbin 的文件.我想搜索 usrbin 并将其替换为 /usr/bin/.

I have a file that contains the string usrbin. I want to search for usrbin and replace it with /usr/bin/.

我尝试了 :%s/usrbin/usr/bin/g,但显示错误 E488: Trailing characters.

I tried :%s/usrbin/usr/bin/g, but it's showing error E488: Trailing characters.

如何在搜索和替换中包含正斜杠?

How do I include a forward slash in a search and replace?

推荐答案

这里有两种方法:

  • 转义 / 这是默认的替代分隔符::s/usrbin/\/usr\/bin
  • 使用另一个替代分隔符,例如,使用散列 # 字符::s#usrbin#/usr/bin.请注意,有些字符不能用作分隔符:"\|
  • escape the / which is the default substitute separator: :s/usrbin/\/usr\/bin
  • use another substitute separator, e.g., using the hash # character: :s#usrbin#/usr/bin. Note that there are characters that you can't use as a separator: ", \, |

这篇关于如何在 vi 搜索中包含正斜杠 &代替的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆