在vi中,搜索并替换,如何转义'/‘(正斜杠)以使其正确。比方说在一条路径上。
如:/Users/tom/document/pdfs/
:%s//Users/tom/documents/pdfs//<new text>/g --FAILS (obviously)
:%s/\/Users/tom/documents/pdfs\//<new text>/g -- FAILS with a trailing error
:%s/'/Users/tom/documents/pdfs/'/<new text>/g -- FAILS with a trailing error我遗漏了什么?
发布于 2009-11-06 08:34:32
您还需要在内部转义正斜杠。
:%s/\/Users\/tom\/documents\/pdfs\//<new text>/g发布于 2009-11-06 08:36:10
或者,你也可以使用:%s,foo/bar/baz,foo/bar/boz,g --我几乎从不使用斜杠,因为这样可以避免混淆。
发布于 2009-11-06 08:37:28
正如Sarah建议的那样,您需要转义所有的正斜杠。
您可以使用除正斜杠之外的其他字符作为分隔符。如果你的搜索字符串中有很多斜杠,这是很方便的。
:%s#/Users/tom/documents/pdfs/#<new test>#g这在vim中工作得很好。我不是100%确定香草vi。
https://stackoverflow.com/questions/1684628
复制相似问题