12

Vim7.3: 爱你不容易

 4 years ago
source link: https://blog.lilydjwg.me/posts/21020.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Vim7.3b出来后我就急不可耐地体验了把,但因为它的ruby支持中$curbuf.number始终返回零,不仅影响到了Command-T插件,也严重影响了我非常喜欢+常用的LustyExplorer插件——时不时地SEGSEGV一下可不行。

等正式版终于出来后,我又立即下载编译了,结果问题依旧。无奈,我只好自己动手,把LustyExplorer中用到$curbuf.number的地方都换成VIM::evaluate('bufnr("%")')了,但之后还是在调用此插件时经常SEGSEGV,郁闷了,于是换回Vim7.2。

但是Vim7.3真的有些很好的特性啊。此前介绍过的就不重复了,下面说说后来发现的两个我很喜欢的特性。

strwidth()函数

strlen()大家都知道,但它求的是字符串的字节数,而不一定等于字符串的宽度,比如中文就是如此。这会造成无法将内容对齐。于是,用于对齐代码的Align插件在处理CJK字符时(设置let g:Align_xstrlen = 3时)使用了一种很耗时的办法来求字符宽度:将字符串显示在Vim里,然后看它占用了多少虚拟列。

有了Vim7.3的strwidth()等函数就不必这么麻烦了。我去改了相关代码,执行效率提升N倍。

setf补全

setf是设置文件类型的指令。这个我很常用,比如写php文件的HTML部分时为了正确地缩进HTML,我会把文件类型设置成HTML,写PHP部分时还要切回去。写新脚本时由于通常没有文件扩展名,所以Vim无法识别文件类型。这些情况我只好手动:setf xxx了。Vim7.3增加了对此的补全支持,可以少敲点字母了。


所以为了用上Vim7.3,同时又不放弃LustyExplorer插件,我前不久又开始折腾Vim7.3的源代码,最后连gdb都用上了,在段错误时得到以下backtrace结果:

#0  __memset_sse2 () at ../sysdeps/i386/i686/multiarch/memset-sse2.S:160
#1  0x00d1d6ac in Perl_sv_upgrade () from /usr/lib/libperl.so.5.10
#2  0x00d1ea6a in Perl_sv_magicext () from /usr/lib/libperl.so.5.10
#3  0x00d1fc11 in Perl_sv_magic () from /usr/lib/libperl.so.5.10
#4  0x00d21882 in Perl_sv_setiv () from /usr/lib/libperl.so.5.10
#5  0x08203691 in perl_buf_free (bp=0x847b890) at if_perl.xs:638
#6  0x080742e3 in free_buffer (buf=0x847b890) at buffer.c:613
#7  0x08073fec in close_buffer (win=0x0, buf=0x847b890, action=4)
at buffer.c:468
#8  0x08074de8 in do_buffer (action=4, start=0, dir=1, count=0, forceit=1)
at buffer.c:1136
#9  0x0807465e in do_bufdel (command=4, arg=0x84b8aa1 "", addr_count=0,
start_bnr=12, end_bnr=1, forceit=1) at buffer.c:834
#10 0x080cbb2c in ex_bunload (eap=0xbfff9f8c) at ex_docmd.c:4939
#11 0x080c817d in do_one_cmd (cmdlinep=0xbfffa140, sourcing=1,
cstack=0xbfffa148, fgetline=0, cookie=0x0) at ex_docmd.c:2656
#12 0x080c5a56 in do_cmdline (cmdline=0x837c2d0 "bwipeout!", getline=0,
cookie=0x0, flags=11) at ex_docmd.c:1122
#13 0x080c5110 in do_cmdline_cmd (cmd=0x837c2d0 "bwipeout!") at ex_docmd.c:728
#14 0x0820cf98 in vim_command (self=3084803600, str=3084486540) at if_ruby.c:731
#15 0x010619a3 in ?? () from /usr/lib/libruby1.8.so.1.8
---Type <return> to continue, or q <return> to quit---
</return></return>

接着我很快发现了问题——明明是个ruby写的插件,最上面怎么调用到Perl了呢?遂关闭+perl特性重新编译,几天已经过去了,Vim7.3依旧运行良好,没有再出现以下烦人的提示了:

Vim: 拦截到致命信号(deadly signal) SEGV
Vim: 结束。
zsh: segmentation fault  vim

现在我一直在关注 ftp://ftp.vim.org/pub/vim/patches/7.3/,期待着这个问题从根本上解决……


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK