用特殊字符替换vim [英] Substitute in vim, with special characters

查看:48
本文介绍了用特殊字符替换vim的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 vim 中使用替换命令来包含特定模式的所有出现

I am trying to use substitute command in vim to enclose all occurences of a particular pattern

\cite{author1}
\cite{author2}

(\cite{author1})
(\cite{author2})

基于堆栈交换中的其他答案我使用了以下 vim 命令

Based on other answers in stack exchangeI used the following vim command

%s/\\cite{(\w\+)}/(\\cite{\1})/g

但是,没有运气.它说找不到匹配项".我放了两个反斜杠,其中一个应该是转义字符.请帮忙.

But, no luck. It says "no matches found". I put two back slashes, one of which is supposed to be the escape character. Kindly help.

我知道我可以使用其他编辑器来完成这项工作,但我想知道我的错误.谢谢.

I know I could use some other editor and finish the job, but I want to know my mistake. Thank you.

推荐答案

请转义 ()

%s/\\cite{\(\w\+\)}/(\\cite{\1})/g

这篇关于用特殊字符替换vim的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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