Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim CursorLine color change in insert mode

There is good snippet for changing cursor color:

if &term =~ "xterm\\|rxvt"   " use an orange cursor in insert mode   let &t_SI = "\<Esc>]12;orange\x7"   " use a red cursor otherwise   let &t_EI = "\<Esc>]12;red\x7"   silent !echo -ne "\033]12;red\007"   " reset cursor when vim exits   autocmd VimLeave * silent !echo -ne "\033]112\007"   " use \003]12;gray\007 for gnome-terminal endif 

How should I alter this that instead of cursor, CursorLine would change color for example from dark blue to blue?

My complete config is https://bitbucket.org/JackLeo/home-configs/src/5b8faf340f87/.vimrc

like image 660
JackLeo Avatar asked Sep 30 '11 18:09

JackLeo


People also ask

How do I change the cursor in vi editor?

When you start vi , the cursor is in the upper left corner of the vi screen. In command mode, you can move the cursor with a number of keyboard commands. Certain letter keys, the arrow keys, and the Return key, Back Space (or Delete) key, and the Space Bar can all be used to move the cursor when you're in command mode.


1 Answers

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)

like image 167
Zarick Lau Avatar answered Oct 06 '22 01:10

Zarick Lau