VIM 彩虹圆括号自动启动

问题描述:

我正在使用 rainbow_parentheses 插件,我希望它从 VIM 开始.目前,在启动时,没有任何变化;启动后手动调用Load_Rainbow,正常工作.

I'm using the rainbow_parentheses plugin and I'm wishing for it start on VIM start. Currently, on start-up, nothing changes; when Load_Rainbow is called manually after start-up, it works.

相关的vimrc部分如下:

The relevant vimrc section is as follows:

" Rainbow Parentheses options {
    function! Config_Rainbow()
        call rainbow_parentheses#load(0)
        call rainbow_parentheses#load(1)
        call rainbow_parentheses#load(2)
    endfunction

    function! Load_Rainbow()
        call rainbow_parentheses#activate()
    endfunction

    augroup TastetheRainbow
        autocmd!
        autocmd Syntax * call Config_Rainbow()
        autocmd VimEnter * call Load_Rainbow()
    augroup END
" }

根据上面 FDinoff 的检查,此问题似乎是特定于平台的:Win 64bit,已使用 此处此处.在 32 位 gVim 中测试这些设置时证实了这一点.我仍然不确定确切的根本原因,但是我发现了一个解决方法.我认为问题在于 Syntax 和 VimEnter autocmd 事件的顺序,所以解决方案是在 Syntax 事件期间设置 VimEnter autocmd.

As checked by FDinoff above, this issue appears to be platform specific: Win 64bit, as tested with the binaries from here and here. This was confirmed when testing those settings in a 32bit gVim. I'm still unsure of the exact root cause, however I have discovered a work-around. I think the problem is the ordering of the Syntax and VimEnter autocmd events, so the solution is to set the VimEnter autocmd during the Syntax event.

vimrc:

" Rainbow Parentheses options {
    function! Config_Rainbow()
        call rainbow_parentheses#load(0) " Load Round brackets
        call rainbow_parentheses#load(1) " Load Square brackets
        call rainbow_parentheses#load(2) " Load Braces
        autocmd! TastetheRainbow VimEnter * call Load_Rainbow() " 64bit Hack - Set VimEnter after syntax load
    endfunction

    function! Load_Rainbow()
        call rainbow_parentheses#activate()
    endfunction

    augroup TastetheRainbow
        autocmd!
        autocmd Syntax * call Config_Rainbow() " Load rainbow_parentheses on syntax load
        autocmd VimEnter * call Load_Rainbow()
    augroup END

    " rainbow_parentheses toggle
    nnoremap <silent> <Leader>t :call rainbow_parentheses#toggle()<CR>
" }