Customize vim cursor style under Mac OS X Terminal

5,930

Solution 1

You can try this one in your .vimrc:

let &t_SI="\033[4 q" " start insert mode
let &t_EI="\033[1 q" " end insert mode

This will set under line for inset mode and block for normal. More details: http://vt100.net/docs/vt510-rm/DECSCUSR

Also it's possible to play with this command in terminal, where is X can be 0, 1, 2, 3 or 4.

printf '\033[X q'

Solution 2

You may want to try adding this to your vimrc:

if exists('$TMUX')
    let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
    let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
    let &t_SI = "\<Esc>]50;CursorShape=0\x7"
    let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif

That should provide the correct escape sequences for tmux or iTerm.

I also found this plugin that auto changes the cursor based on the current mode.

Share:
5,930

Related videos on Youtube

Xiao Jia
Author by

Xiao Jia

In 2016 I founded Pygmal Technologies. Our flagship product is the SPACE operating environment in virtual reality.

Updated on September 18, 2022

Comments

  • Xiao Jia
    Xiao Jia over 1 year

    I want to customize the vim cursor to be a blinking rectangle block. I tried this and this and many other similar stuffs after some searches, but none of them works as expected.

    Currently my cursor is an non-blinking underline in grey (i.e. the underline below character "e" in the last line below), which is pretty hard to recognize.

    underline cursor

    When the cursor is over a parenthesis character, it becomes a block. (Actually I believe this is a change in background color) What I want is to have this block all the time, and blinking.

    block cursor

    I have nothing related to cursor style in my .vimrc file. I am using Mac OS X 10.9, Terminal Version 2.4 (326), and oh-my-zsh. In Terminal settings, I use Pro theme and set cursor to underline. I can change this to block so the cursor in vim changes as well, but I need the underline cursor in a normal Terminal.

    terminal settings

  • Xiao Jia
    Xiao Jia about 10 years
    It doesn't work. I use neither tmux nor iTerm. I am using the Terminal.app provided by Mac OS X and zsh.
  • ostler.c
    ostler.c almost 10 years
    Found this post and am using tmux - works great thanks!
  • krry
    krry about 5 years
    The \033 escape character was the crux for me. The other suggestions using \<Esc>Ptmux;\<Esc>\<Esc> didn't work on OSX Terminal.app with Tmux, zsh, vim.