这是 Vim 字符串表达式求值中的错误吗?
我正在调试 Arch Linux 上 Vim73 中运行的插件的问题,它似乎源于字符串表达式求值中的错误。
在此 Vim 安装中,表达式 'xxx' > ''
的计算结果为 0(假),而在所有其他 Vims 中,我看到该表达式的计算结果(正如它应该的那样)为 1(真)。
有谁知道这的解释吗? Arch Linux Vim 编译时并没有内置很多功能,但是真的有一些功能可以改变字符串表达式的计算吗?
是否有一些 Vim 设置(编码?)可能改变了这个字符串比较的结果?这是 Vim 的简单安装(vimrc 中没有任何值得注意的内容),给出了糟糕的结果,没有看到任何可以更改设置的地方,即使有一些设置会影响这个结果。
感谢您提供任何信息。
更新: 事实证明,这个问题是由最近版本的 64 位 Vim 中设置 Vim 标志“ignorecase”时字符串比较函数中的错误引起的。无论是否忽略大小写,非空字符串都应该大于空字符串,但 Vim 返回 false。错误报告在这里: http://groups.google.com/group/vim_dev/browse_thread/thread/313bc7c46a19cd40
解决方法是:(1) 使用强制进行“matchcase”比较的比较运算符,例如 mystring_var ># ''
或 (2) 使用 !empty(mystring_var)< /代码> .
I was debugging a problem with a plugin running in Vim73 on Arch Linux and it seems to stem from an error in string expression evaluation.
In this Vim installation the expression 'xxx' > ''
evaluates to 0 (false) while in all other Vims I've seen the expression evaluates (as it should) to 1 (true).
Does anyone know the explanation for this? The Arch Linux Vim was not compiled with lots of features built in, but could there really be some feature that changes the evaluation of string expressions?
Is there some Vim setting (encoding?) that might have changed the result of this string comparison? It was a plain-jane install of Vim (nothing of note in vimrc) giving the bad result, didn't see anwhere a setting could have been changed even if there is some setting that affects this result.
Thanks for any info.
UPDATE:
It turns out this problem was caused by a bug in the string comparison function in recent version of 64-bit Vim when the Vim flag 'ignorecase' is set. A non-empty string should be greater than an empty string regardless of whether case is ignored, but Vim was returning false. Bug report is here:
http://groups.google.com/group/vim_dev/browse_thread/thread/313bc7c46a19cd40
Workarounds would be: (1) use comparison operator that forces 'matchcase' comparison, e.g., mystring_var ># ''
or (2) use !empty(mystring_var)
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要知道这个问题的答案,您必须查看文档。这是
*41.4* 条件
的引用部分:显然,vim 不保证您尝试执行的操作的结果,您不应该依赖它。如果你想比较字符串的长度,请查看
*strlen()*
。To know the answer for this question you have to take a look at the documentation. Here is a quote of the
*41.4* Conditionals
section:Apparently, vim does not guarantee the result for the operation you are trying to perform and you shouldn't rely on it. If you want to compare the length of the strings, take a look at
*strlen()*
.