I would like to know how to change, if possible, the cursor in Vim (in color, shape, etc.) depending on what mode you are in.
I am constantly forgetting that I am not
I usually have the current vim mode onto statusline, among other things. If you seek simplicity, you can set only this information onto the statusline.
However, usually the really crazy things happen when you have caps lock depressed and are in command mode (since hjkl now are HJKL - just J and K is enough to make you pull your hair out when you don't understand what's happening. Do a :h J
and :h K
to see what I mean). Just beware the caps lock key and you'll be fine most of the time IMO.
If you are using tmux and iTerm2 on macOS,
the following changes the cursor from a block to a cursor and highlights the current line
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
:autocmd InsertEnter * set cul
:autocmd InsertLeave * set nocul
credit: https://gist.github.com/andyfowler/1195581
To change the shape of the cursor in different modes, you can add the following into your .vimrc
file.
For the GNOME Terminal (version 2.26):
if has("autocmd")
au InsertEnter * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
au InsertLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape block"
au VimLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
endif
If you use more than one profile in GNOME Terminal, you might have to adapt this to your profiles.
For Konsole in KDE4:
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
This works with multiple tabs and windows.
See also: “Change cursor shape in different modes” on Vim Tips Wiki.
You may try the Terminus Vim plugin:
In insert mode, the cursor shape changes to a thin vertical bar. In replace mode, it changes to an underline. On returning to normal mode, it reverts to the standard "block" shape.
I find it useful to only have the cursor blinking in Insert mode and keep it static in other modes.
set guicursor+=n-v-c:blinkon0