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

后端 未结 11 717
无人及你
无人及你 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:21

    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.

    0 讨论(0)
  • 2020-12-04 11:23

    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

    0 讨论(0)
  • 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 = "\<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.

    0 讨论(0)
  • 2020-12-04 11:24

    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.

    0 讨论(0)
  • 2020-12-04 11:25

    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
    
    0 讨论(0)
提交回复
热议问题