gpt4 book ai didi

triggers - vim 进入可视模式时运行命令

转载 作者:行者123 更新时间:2023-12-04 05:53:30 25 4
gpt4 key购买 nike

我使用一个小脚本来触发插入模式以更改行号颜色:

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() 即时一旦我激活任何视觉模式?

最佳答案

:help 待了一段时间后我以以下设置结束:

" Colorize line numbers in insert and visual modes
" ------------------------------------------------
function! SetCursorLineNrColorInsert(mode)
" Insert mode: blue
if a:mode == "i"
highlight CursorLineNr ctermfg=4 guifg=#268bd2

" Replace mode: red
elseif a:mode == "r"
highlight CursorLineNr ctermfg=1 guifg=#dc322f

endif
endfunction


function! SetCursorLineNrColorVisual()
set updatetime=0

" Visual mode: orange
highlight CursorLineNr cterm=none ctermfg=9 guifg=#cb4b16
endfunction


function! ResetCursorLineNrColor()
set updatetime=4000
highlight CursorLineNr cterm=none ctermfg=0 guifg=#073642
endfunction


vnoremap <silent> <expr> <SID>SetCursorLineNrColorVisual SetCursorLineNrColorVisual()
nnoremap <silent> <script> v v<SID>SetCursorLineNrColorVisual
nnoremap <silent> <script> V V<SID>SetCursorLineNrColorVisual
nnoremap <silent> <script> <C-v> <C-v><SID>SetCursorLineNrColorVisual


augroup CursorLineNrColorSwap
autocmd!
autocmd InsertEnter * call SetCursorLineNrColorInsert(v:insertmode)
autocmd InsertLeave * call ResetCursorLineNrColor()
autocmd CursorHold * call ResetCursorLineNrColor()
augroup END

为了在离开可视模式后恢复行号的颜色,我必须执行以下步骤:
  • 重新映射相关键绑定(bind)以调用“输入视觉功能”
  • 进入视觉模式时,功能设置 updatetime=0对于 CursorHold事件
  • 通过 autocmd CursorHold 调用“离开视觉功能”
  • 离开视觉模式时,功能会重置 updatetime=4000对于 CursorHold事件
  • 关于triggers - vim 进入可视模式时运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15561132/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com