替换Vim中字符串周围的引号? [英] Replacing quote marks around strings in Vim?

查看:541
本文介绍了替换Vim中字符串周围的引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些类似于<Foobar Name='Hello There'/>的东西,需要将单引号更改为双引号.我尝试了:s/\'.*\'/\"\0\",但是最终生成了<Foobar Name="'Hello There'"/>.将\0替换为\1只会在双引号内产生一个空白字符串-是否缺少某些特殊的语法,我只需要将引号内的找到的字符串("Hello There")分配给\1?

I have something akin to <Foobar Name='Hello There'/> and need to change the single quotation marks to double quotation marks. I tried :s/\'.*\'/\"\0\" but it ended up producing <Foobar Name="'Hello There'"/>. Replacing the \0 with \1 only produced a blank string inside the double quotes - is there some special syntax I'm missing that I need to make only the found string ("Hello There") inside the quotation marks assign to \1?

推荐答案

您需要使用分组:

:s/\'\(.*\)\'/\"\1\"

这样,参数1(即\ 1)将对应于由\(和\)分隔的任何内容.

This way argument 1 (ie, \1) will correspond to whatever is delimited by \( and \).

这篇关于替换Vim中字符串周围的引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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