vim - 宏中替换失败后的vim替换
问题描述
我在宏中有大量查找和替换
:let@m=':%s/√/\\sqrt/g
:%s/∫/\\int/g
:%s/∑/\\sum/g
:%s/∏/\\prod/g
:%s/⋃/\\bigcup/g
:%s/⋂/\\bigcap/g
:%s/∪/\\cup/g
:%s/∩/\\cap/g
:%s/∂/\\partial/g
:%s/–/\--/g
:%s/—/\---/g
:%s/•/\\bullet/g
:%s/·/\\cdot/g
:%s/◦/\\circ/g
:%s/±/\\pm/g
:%s/∓/\\mp/g
<more stuff/>
'
如果这些查找和替换中的任何一个失败(例如,如果文件中没有 ∫),则后续的不会运行。我怎样才能:%s///g
安静地、非破坏性地失败?
解决方案
来自:help :s_flags
:
[e] When the search pattern fails, do not issue an error message and, in
particular, continue in maps as if no error occurred. This is most
useful to prevent the "No match" error from breaking a mapping.
所以:
%s/√/\\sqrt/ge
%s/∫/\\int/ge
…
推荐阅读
- c++ - 当我有多态指针时使用“零规则”
- javascript - 如何从一个特定对象返回值?
- r - 从子集数据框创建新数据框
- google-apps-script - Google Apps 脚本中的缓存是否有限制?
- java - 安装插件后无法使用依赖项 Spring-boot 打包 jar
- c# - 数据表未加载说等待激活json
- javascript - How can I compare a string A1 with a value A2 (index 0's) in and array values?
- python - 如何通过xpath从scrapy的源代码中提取部分?
- java - 如何转换getter的返回值
- c++ - 用 32 位原子实现 64 位原子计数器