Last active
December 19, 2015 03:39
-
-
Save koturn/5891492 to your computer and use it in GitHub Desktop.
NeoBundleにより、インサートモード時にプラグインの遅延ローディングを行った場合における、
挿入モード時のステータスラインの色の自動変更が行われない問題の解決方法。
WIndows7のvim/gvim, Windows7-Cygwin上のvimでこの問題が起こっていた。
私はWindowsユーザであるため、他の環境で起こる問題であるかどうかは不明。 挿入モード時のステータスラインの色変更について:
https://sites.google.com/site/fudist/Home/vim-nihongo-ban/vim-color#color-insertmode
This file contains hidden or 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}} | |
augroup MyAutoCmd | |
autocmd! | |
augroup END | |
" ==================================================================== | |
" NeoBundleにより、インサートモード時にプラグインの遅延ローディングを | |
" 行った場合、挿入モード時のステータスラインの色の自動変更が | |
" 行われない。 | |
" なので、以下のautocmdの指定により、カラースキームを再度読み込み、 | |
" (無理矢理)回避する。 | |
" ==================================================================== | |
let s:insert_cnt = 0 | |
let s:cs_name = '' | |
autocmd MyAutoCmd InsertEnter * call s:insert_fook_fixer() | |
function! s:insert_fook_fixer() | |
if s:insert_cnt == 0 | |
let s:insert_cnt = 1 | |
let s:cs_name = s:getColorScheme() | |
elseif s:insert_cnt == 1 | |
exec 'colorscheme ' . s:cs_name | |
unlet s:cs_name | |
let s:insert_cnt = 2 | |
endif | |
endfunction | |
function! s:getColorScheme() | |
let l:cs_name = '' | |
redir => l:cs_name | |
silent colorscheme | |
redir END | |
return substitute(l:cs_name, '[\r\n]', '', 'g') | |
endfunction | |
" ==================================================================== | |
" ノーマルモード、インサートモードでステータスバーの色を変更する | |
" ==================================================================== | |
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 | |
" Change color of status line depending on mode. | |
if has('syntax') | |
augroup MyAutoCmd | |
au InsertEnter * call s:statusLine(1) | |
au InsertLeave * call s:statusLine(0) | |
augroup END | |
endif | |
let s:slhlcmd = '' | |
function! s:statusLine(mode) | |
if a:mode == 1 | |
silent! let s:slhlcmd = 'highlight ' . s:getHighlight('StatusLine') | |
highlight StatusLine guifg=white guibg=MediumOrchid gui=none ctermfg=white ctermbg=DarkRed cterm=none | |
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