Vim CursorLine color change in insert mode

前端 未结 5 410
天命终不由人
天命终不由人 2021-01-30 11:29

There is good snippet for changing cursor color:

if &term =~ \"xterm\\\\|rxvt\"
  \" use an orange cursor in insert mode
  let &t_SI = \"\\]12         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 12:11

    Have you look in into the 'highlight' command which is a easier way to control this.

    For example, to change the CursorLine,

    :hi CursorLine guifg=red guibg=blue
    

    Reference: :help highlight

    To make it switch between mode.

    " Enable CursorLine
    set cursorline
    
    " Default Colors for CursorLine
    highlight  CursorLine ctermbg=Yellow ctermfg=None
    
    " Change Color when entering Insert Mode
    autocmd InsertEnter * highlight  CursorLine ctermbg=Green ctermfg=Red
    
    " Revert Color to default when leaving Insert Mode
    autocmd InsertLeave * highlight  CursorLine ctermbg=Yellow ctermfg=None
    

    I may be possible to mix termcap color with autocmd, but IMO, highlight is more easy to maintain in long term (and in case if use gVim occassionally)

提交回复
热议问题