执行包含 '/' 字符的 vim 替换命令 [英] Execute vim substitute command that includes '/' characters

查看:57
本文介绍了执行包含 '/' 字符的 vim 替换命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 java 文件,我在其中写了/t,而不是 \t,这是制表符转义函数的正确表示法.我想使用 vim 的替换功能 (:s) 但是当我做这样的事情时:

I have a java file in which I wrote /t, instead of \t, the proper notation of the tab escape function. I want to use vim’s substitution feature (:s) but when I do something like this:

:%s//t/\t/g

我收到错误信息E488:尾随字符

I get the error message E488: Trailing characters

如何编写命令以便执行替换?谢谢.

How can I write the command such that I can execute the substitution? Thank you.

推荐答案

使用反斜杠转义字符.所以:

Use backslash to escape the characters. So:

:%s/\/t/\\t\g

您也可以使用不同的分隔符,例如:

You can also use a different delimiter like:

:%s@/t@\\t@g

这篇关于执行包含 '/' 字符的 vim 替换命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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