在 vim 中执行非正则表达式搜索/替换 [英] Perform a non-regex search/replace in vim

查看:61
本文介绍了在 vim 中执行非正则表达式搜索/替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 vim 中进行搜索/替换时,我几乎从不需要使用正则表达式,所以不断地逃避一切是一种痛苦,有没有办法让它默认不使用正则表达式,或者有没有替代命令来完成这个?

When doing search/replace in vim, I almost never need to use regex, so it's a pain to constantly be escaping everything, Is there a way to make it default to not using regex or is there an alternative command to accomplish this?

举个例子,如果我想用 &lt; 替换 <,我只想输入 s/</&lt;/g 而不是 s/\</\&lt\;/g

As an example, if I want to replace < with &lt;, I'd like to just be able to type s/</&lt;/g instead of s/\</\&lt\;/g

推荐答案

对于 :s 命令,有一个禁用或强制魔法的快捷方式.要关闭魔法,请使用 :sno 像:

For the :s command there is a shortcut to disable or force magic. To turn off magic use :sno like:

:sno/search_string/replace_string/g

在这里找到:http://vim.wikia.com/wiki/Simplifying_regular_expressions_using_magic_and_no-magic

这篇关于在 vim 中执行非正则表达式搜索/替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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