简体   繁体   English

Vim转义反斜线粘贴

[英]Vim escape backslash paste

I am having the following text in vim: 我在vim中有以下文本:

Hello, \/Good\/Bye.

Now I want to change it to: 现在,我想将其更改为:

Hello, -Good-Bye.

So I use: Visual Select, Yank the Line. 因此,我使用:视觉选择,拉线。 then 然后

%s/<Ctrl+R>+"/-/gc

When I push CTRL+R+" The line clones into the search, but It \\/ will not work. I need to change it to \\\\/ . Is there a quick function or keystroke to automatically escape the chars? Please let me know. Thank you! 当我按CTRL+R+"该行会克隆到搜索中,但它\\/将不起作用。我需要将其更改为\\\\/ 。是否有快速功能或按键来自动转义字符?请让我知道。谢谢!

As phd wrote in comments, you can use \\V and escape() to do it. 正如phd在注释中所写,您可以使用\\Vescape()来做到这一点。 For example, write the following function: 例如,编写以下函数:

function! Regesc(text)
    return '\V' . escape(a:text, '/\')
endf

Then after yanking some text, use it like this: 然后,在拉动一些文本之后,像这样使用它:

:%s/ Ctrl+R =Regesc(@@) CR /-/gc CR :%s/ Ctrl + R =Regesc(@@) CR /-/gc CR

This will display and run the following command, depending of what you yanked: 这将显示并运行以下命令,具体取决于您要删除的内容:

:%s/\\VHello, \\\\\\/Good\\\\\\/Bye./-/gc

You could use another delimiter after your visual selection 您可以在视觉选择后使用另一个定界符

:'<,'>s,\%V\\/\%V,-,gc

\\ ......... scaped backslash
\%V ........ visual selection area

So you have to put your pattern \\\\/ inside a visual delimiter 因此,您必须将样式\\\\/放在视觉分隔符内

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM