Created
June 29, 2013 20:16
-
-
Save koturn/5892503 to your computer and use it in GitHub Desktop.
NeoBundleのautoloadで、インサートモード時にプラグインを読み込む場合に、問題が発生する最小コードです。インサートモード時に、ステータスラインのカラーを変更する処理がうまく動作しなくなります。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let $DOTVIM = $HOME . '/.vim' | |
if has('vim_starting') | |
set runtimepath+=$DOTVIM/bundle/neobundle.vim | |
endif | |
call neobundle#rc(expand('$DOTVIM/bundle/')) | |
NeoBundle 'Shougo/neobundle.vim' | |
NeoBundleLazy 'Shougo/neocomplete.vim', | |
\ {'autoload' : {'insert' : 1} | |
\} | |
" ==================================================================== | |
" インサートモードでステータスバーの色を変更する | |
" NeoBundleでインサートモード時に読み込むプラグインが1つでもあると、 | |
" うまく動作しなくなる。 | |
" ==================================================================== | |
set laststatus=2 | |
set statusline=%<%f\ %m\ %r%h%w%{'[fenc='.(&fenc!=#''?&fenc:&enc).']\ [ff='.&ff.']\ [ft='.(&ft==#''?'null':&ft).']\ [ascii=0x'}%B]%=\ (%v,%l)/%L%8P | |
let g:hi_insert = 'highlight StatusLine guifg=darkblue guibg=darkyellow gui=none ctermfg=blue ctermbg=yellow cterm=none' | |
if has('syntax') | |
augroup InsertHook | |
autocmd! | |
autocmd InsertEnter * call s:StatusLine('Enter') | |
autocmd InsertLeave * call s:StatusLine('Leave') | |
augroup END | |
endif | |
let s:slhlcmd = '' | |
function! s:StatusLine(mode) | |
if a:mode ==# 'Enter' | |
silent! let s:slhlcmd = 'highlight ' . s:GetHighlight('StatusLine') | |
silent exec g:hi_insert | |
else | |
highlight clear StatusLine | |
silent exec s:slhlcmd | |
endif | |
endfunction | |
function! s:GetHighlight(hi) | |
redir => hl | |
exec 'highlight ' . a:hi | |
redir END | |
let hl = substitute(hl, '[\r\n]', '', 'g') | |
let hl = substitute(hl, 'xxx', '', '') | |
return hl | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment