如何在 vi 中转义斜线字符?

发布于 2024-08-05 01:36:56 字数 82 浏览 1 评论 0原文

当我尝试在 vi 中搜索以斜杠/字符开头的字符串时,光标会从上一个搜索跳转到下一个搜索结果。但是,我想找到字面斜杠字符。这怎么能做到呢?

When I try to search a string starting with the slash / character in vi, the cursor jumps to the next search result from the previous search. However, I'd like to find the literal slash character. How can this be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

扛起拖把扫天下 2024-08-12 01:36:56

输入:

/\/

Type this:

/\/
摇划花蜜的午后 2024-08-12 01:36:56

如果使用 ,则不需要转义 /

?/home/my_user/ # and enter to search backwards
/               # and enter to search forwards

请参阅 这里

You would not need to escape / if you use ?

?/home/my_user/ # and enter to search backwards
/               # and enter to search forwards

See here.

向地狱狂奔 2024-08-12 01:36:56

使用反斜杠。

:/\/

这将向前搜索到下一个正斜杠。

Use a backslash.

:/\/

This will search forward to the next forward slash.

孤者何惧 2024-08-12 01:36:56

我在这方面花了太多时间,所以让我在这里快速回答一下。 vi 中的转义字符(我认为也是 vim,我在这里使用的是 CentOS 盒子)是“\”,根据 lutz 8 年前的回答。我有一些在 Windows 中构建的东西,正在转换到 Linux。通常,您可能有一个具有绝对目录位置的文件,并且您希望将斜杠从“\yatta\yatta\blah...”转换为“/yatta/yatta/blah...”(所有行中都出现)。对于 vi,所有行都是 %s,尾随 g 表示每行中出现的所有情况。因此,使用 vi 或 vim 编辑文件,然后按转义键和冒号以获得“:”提示符,然后输入:

%s/\\/\//g

所有“\”字符都更改为“/”。但您可能仍然需要将“c:”引用更改为“/home/prod”或类似的内容,以位于“/yatta/yatta/blah...”前面。简单的。 vi 转义字符是“\”,因此您按 esc,然后输入“:”跳转到 vi cmd 输入模式,然后输入:

%s/c:/\/home\/prod/g

有很多可用的 vi/vim 命令的快速“备忘单”。它是一个无处不在的工具,几乎可以在每个 Linux/Unix 系统上使用,甚至可以在越狱的 iPad 等上使用。

I spent too much time on this, so let me put the quick answer here. The escape char in vi (vim also, I think, I am using a CentOS box here) is "\", as per lutz's answer from 8 years ago. I have this stuff that was built in Windows, am converting to Linux. Typically, you might have a file with absolute directory locations, and you want to convert the slashes from "\yatta\yatta\blah..." to "/yatta/yatta/blah...", all occurances in all lines. For vi, all lines is %s, and the trailing g means all occurances within each line. So, edit your file with vi or vim, and press escape and colon to get the ":" prompt, and enter:

%s/\\/\//g

All the "\" chars get changed to "/". But you may still need to change the "c:" references to "/home/prod" or something like that, to sit in front of "/yatta/yatta/blah...". Easy. The vi escape char is "\", so you press esc, and enter ":" to jump to vi cmd entry mode, and enter:

%s/c:/\/home\/prod/g

There are lots of quicky "cheat-sheets" of vi/vim commands available. It is a ubiquitous tool, available on virtually every Linux/Unix system - even on jailbroken iPads and such.

安静被遗忘 2024-08-12 01:36:56

--- 哎呀,抱歉,我输入了替换信息。使用 \ 转义仅适用于搜索

使用不同的分隔符

:%s./.z.

将用字母 z 替换所有 '/'

--- oops, sorry, I entered info for replace. Escaping with \ is better for search only

Use a different separator

:%s./.z.

will replace all '/' with the letter z

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文