在vim中,是否有一个插件可以使用%来匹配相应的双引号(“)? [英] In vim, is there a plugin to use % to match the corresponding double quote (")?

查看:178
本文介绍了在vim中,是否有一个插件可以使用%来匹配相应的双引号(“)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

键是vim的最佳功能之一:它使您可以从{跳转到},从[跳转到],依此类推.

The % key is one of the best features of vim: it lets you jump from { to }, [ to ], and so on.

但是,默认情况下,它不能使用引号:"',可能是因为开始和结束引号是同一字符,使实现更加困难.

However, it does not work by default with quotes: Either " or ', probably because the opening and closing quote are the same character, making implementation more difficult.

更多地考虑这个问题,我相信应该通过计算前面引号的数量是奇数还是偶数,并相应地跳到上一个或下一个引号来实现该问题.

Thinking a bit more about the problem, I'm convinced that it should be implemented, by counting if the number of preceding quotes is odd or even and jumping to the previous or next quote, accordingly.

在我尝试自己实现它之前,我想知道是否有人已经拥有它?

Before I try to implement it myself, I'd just like to know if someone already has?

推荐答案

根据您需要这样做的原因,可能会有更好的方法来完成您要寻找的东西.例如,如果您具有以下代码:

Depending on your reason for needing this, there may be a better way to accomplish what you're looking for. For example, if you have the following code:

foo(bar, "baz quux")
              ^

,而您的光标恰巧在^上,并且您想将引号内的所有内容替换为其他内容,请使用ci".这使用Vim 文本对象" 进行更改(c) (i)中的所有内容都用引号(")括起来,并使您进入插入模式,如下所示:

and your cursor happens to be at the ^, and you want to replace everything inside the quotes with something else, use ci". This uses the Vim "text objects" to change (c) everything inside (i) the quotes (") and puts you in insert mode like this:

foo(bar, "")
          ^

然后,您可以开始输入替换文本.还有许多其他文本对象对于这种快捷方式确实很有用.每周学习(并使用)一个新的Vim命令,您将立即成为专家!

Then you can start typing the replacement text. There are many other text objects that are really useful for this kind of shortcut. Learn (and use) one new Vim command per week, and you'll be an expert in no time!

这篇关于在vim中,是否有一个插件可以使用%来匹配相应的双引号(“)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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