为什么是ci"和 ci(, ci{.... 表现不同? [英] Why ci" and ci(, ci{.... behave differently?

查看:30
本文介绍了为什么是ci"和 ci(, ci{.... 表现不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都知道 ci" ci' ci( ci[ ... 做了什么.非常方便在日常编辑中,发现了一些奇怪的东西,查看了帮助,没有找到原因.

we all know what ci" ci' ci( ci[ ... does. Very handy in everyday's editing. I found something strange, and checked the help, didn't find out why.

说,我有一个文件:

foo "target"
foo 'target'
foo (target)
foo {target}
foo [target]
foo <target>

如果我的光标位于每一行的开头,(在f"上),那么我输入 ci", ci', ci(...

if my cursor at the beginning of each line, (on the 'f'), then I type ci", ci', ci(...

cix 仅适用于引号(单引号或双引号),不适用于括号.为什么他们的行为不同?

the cix works only with quotes (single or double), doesn't work for brackets. why do they behave differently?

(dix, vix 同)

使用--noplugin、vim 7.3 测试

tested with --noplugin, vim 7.3

谢谢.

更新

感谢@romainl 的回答.我对vim中的成对处理"仍有疑问

thanks @romainl for the answer. I still have doubt regarding the "pair processing in vim"

检查这个例子:

foo "targ"eti" some"thing else "

如果我有像上面这样的一行,我输入ci",无论光标在开头还是在引号之间,它都能完美运行,似乎vim确实有pair"的想法?

if I have a line like above, I type ci", no matter cursor is at beginning or between quotes, it works perfectly, it seems that vim does have the idea of "pair"?

这也许是你对配对的意思?

and this maybe what you meant about the pairing ?

foo "target x some"thing else "
foo (target x some(thing else )

我有上面两行,如果(光标在 x 处)我输入 ci"ci(,第二行没有任何反应,但第一行变成了:

I have above two lines, if (cursor at x) I type ci" and ci(, nothing happened to 2nd line, but first line changed into:

foo "I"thing else " (I is cursor)

推荐答案

ci(ci[, ci{ 一致code>cit 和所有其他 i.只有 ci'ci" 像它们一样工作做.这里的异常值是引号,而不是括号.

ci( is consistent with ci[, ci{ and cit and all the other <action>i<something>. Only ci' and ci" work like they do. The outliers are the quotes, here, not the brackets.

Vim 不认为引号是成对出现的,而括号则是.它具有匹配对的内部逻辑,该逻辑适用于实际对,但不适用于引号,因此行为不同.

Vim doesn't consider that quotes come in pairs while brackets do. It has an internal logic for matching pairs that works with actual pairs but not with quotes hence the difference in behavior.

您不是第一个抱怨这种差异的人:这是一个解决方案,也许您可​​以找到其他解决方案.

You are not the first to complain about that discrepancy: this is one solution, maybe you can find others.

编辑

不幸的是,我对 Vim 的内部结构没有深入了解,所以我只能在这里做出假设.

I don't have a deep knowledge of Vim's internals, unfortunately, so I can only make assumptions, here.

如果你让 Vim 做 ci",它会尽力找到一对双引号,但双引号不能成对出现:没有办法判断一个 " 是与括号相反的结尾或开头.因此,Vim 必须做出一些选择.IMO,考虑到家庭其他成员的工作方式,最有意义的选择是假设光标位于引号之间,并从第一个到右侧的第一个到左侧的第一个中进行选择.我只能假设这种方法在某些方面被证明是错误的,或者由于某种原因不起作用,而另一种方法(当前的方法)占了上风.

If you ask Vim to do ci" it does its best to find a pair of double quotes but double quotes don't go by pairs: there's no way to tell if a " is the closing one or the opening one contrary to brackets. Because of that, Vim must make some choices. IMO, the choice that would make the most sense considering how the other members of the family work, would be to assume that the cursor is between the quotes and select from the first one to the right to the first one to the left. I can only assume that this method proved wrong in some way or didn't work for some reason and that the other method (the current one) prevailed.

另一种解释可能是 i 机制以某种方式绑定到无法正确处理的特定子系统(可能与 showmatch 相同?)引号.

Another explanation could be that the i<something> mechanism is somehow tied to a specific subsystem (maybe the same as showmatch?) that is unable to deal correctly with quotes.

无论如何,就像你一样,我发现这种差异很奇怪,我以某种方式将它内化,并将我对 <action>i" 的使用与其他人的工作方式保持一致.实际上做 2t"ci" 或一些变体而不是 ci" !!效率低下,我知道.

Anyway, just like you, I find this discrepancy weird and I've somehow internalized it and aligned my usage of <action>i" to how the others work. To the point of actually doing 2t"ci" or some variant instead of ci"!! Inefficient, I know.

你读过:h a'吗?我完全忘记了我对这个问题的有限理解"是从哪里得到的,但它就在那里!它说:

Did you read :h a'? I completely forgot where I got my "limited understanding" of the issue but it was there! It says:

只在一行内有效.当光标从引号开始时,Vim 将通过从行的开头搜索来确定哪些引号对构成了一个字符串."

"Only works within one line. When the cursor starts on a quote, Vim will figure out which quote pairs form a string by searching from the start of the line."

我从中得到的是:由于某些我们不知道的原因,Vim 使用另一种机制来匹配引号而不是其他对,这就是为什么 ci"cib 不同和朋友们.根本原因尚不清楚,但我相当确定大局看起来很像我想象的那样.

What I get from that is this: for some reasons unknown to us, Vim uses another mechanism for matching quotes than for the other pairs and that is why ci" is different from ciband friends. The underlying cause is not clear at all but I'm fairly certain that the big picture looks a lot like what I imagine.

对我来说,它看起来很像一个错误或伪装成功能的限制.

To me, it looks a lot like a bug or a limitation disguised as a feature.

如果你仍然好奇,我建议你在 vim-dev 上进一步提问.

If you are still curious, I'd suggest you ask any further question on vim-dev.

这篇关于为什么是ci"和 ci(, ci{.... 表现不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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