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

我有一个包含字符串 usrbin的文件。我想搜索 usrbin并用 /usr/bin/替换它。

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

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

87703 次浏览

Here are two ways:

  • 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: ", \, |

You can review this in the help subsystem using :h pattern-delimiter