osx - Customize vim cursor style under Mac OS X Terminal

06
2014-04
  • Xiao Jia

    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

  • Answers
  • Nate Mara

    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.


  • Related Question

    ubuntu - Colors in Vim via gnome terminal are not the same with gVim
  • user22727

    why is it that the colors when using the color scheme 'blackboard' via Vim in gnome terminal is not the same as when I use the same theme in gVim? i.e. the background is black while on gVim it's blue and the function names are not colroed etc. Only a few parts of teh code are colored.

    Here's my .vimrc

    filetype plugin indent on
    set number
    let &t_Co=256
    

    Also on my Profile Preferences > Colors tab, I got: Bulit-in Schemes: Green on Black Built-in schemes: XTerm


  • Related Answers
  • Simon Walker

    Take a look at CSApprox - very good at matching colourschemes (in linux at least - in OSX the default terminal does not have enough colours)

    Fairly simple to set up - just configure how many colours are usable by your terminal and put the needed information in your .vimrc

  • Tadeusz A. Kadłubowski

    Vim running in a terminal emulator uses so-called ANSI codes to display color. gVim doesn't relay on terminal emulation, and can use any RGB color it likes.

    In the color scheme declaration that's guifg & guibg entries for gVim, and ctermfg & ctermbg entries for terminal emulators. See

    :help syntax
    

    for more details about differences between syntax highlighting between vim working inside a terminal emulator and as a standalone GUI program.

  • mrucci

    Take a look at this vim tips wiki page were two solutions for making consistent colorschemes between terminals and GUI are discussed.