我使用一个小脚本来触发插入模式以更改行号颜色:
function! CursorLineNrColorInsert(mode)
" Insert mode: blue
if a:mode == "i"
highlight CursorLineNr ctermfg=4
highlight CursorLineNr guifg=#268bd2
" Replace mode: red
elseif a:mode == "r"
highlight CursorLineNr ctermfg=1
highlight CursorLineNr guifg=#dc322f
else
highlight CursorLineNr ctermfg=0
highlight CursorLineNr guifg=#073642
endif
endfunction
autocmd InsertEnter * call CursorLineNrColorInsert(v:insertmode)
autocmd InsertLeave * highlight CursorLineNr ctermfg=0
autocmd InsertLeave * highlight CursorLineNr guifg=#073642
当我进入任何插入模式并在正常模式下恢复为原始颜色时,它工作得很好并且会立即更改我的行号。
我想对视觉模式做同样的事情:
function! CursorLineNrColorVisual(mode)
" Visual mode: orange
if mode()=~#"^[vV\<C-v>]"
highlight CursorLineNr ctermfg=9
highlight CursorLineNr guifg=#cb4b16
else
highlight CursorLineNr ctermfg=0
highlight CursorLineNr guifg=#073642
endif
endfunction
autocmd CursorMoved * call CursorLineNrColorVisual(mode())
基本上这有效,但不是立即生效,因为该功能是在CursorMoved
. 一旦激活任何视觉模式,我怎么能CursorLineNrColorVisual()
立即开火?