How do I change the cursor between Normal and Insert modes in Vim?

后端 未结 11 789
无人及你
无人及你 2020-12-04 10:56

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

11条回答
  •  星月不相逢
    2020-12-04 11:24

    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 = "\]50;CursorShape=1\x7"
    let &t_EI = "\]50;CursorShape=0\x7"
    

    This works with multiple tabs and windows.

    See also: “Change cursor shape in different modes” on Vim Tips Wiki.

提交回复
热议问题