How can I have different cursor shapes when running vim inside tmux under cygwin?

WITHOUT tmux these lines would be enough to achieve what I want:

let &t_SI = "\e[5 q"
let &t_EI = "\e[2 q"

But somehow my tmux breaks it - cursor has block shape no matter what vim mode I'm in.

My specs:

  • Windows 7 x64
  • Cygwin x86
  • TMUX 1.9a
  • Vim 7.4.726 (compiled with +cursorshape)
  • terminal emulator: mintty 1.1.3
  • used in Cygwin Terminal or Cmder (either way, cursor shapes work only without TMUX)
  • echo $TERM gives me screen-256color (in TMUX and outside of it, because i have export TERM=screen-256color in my .bashrc
  • .tmux.conf contains:
    set -g default-terminal "screen-256color" setw -g xterm-keys on

What i tried already without success:

  • export TERM=xterm
  • export TERM=vt100
  • "rightclick on bar > Options > Looks > Cursor" (it changes the cursor permanently, vim modes still don't change it)
  • Vim compiled with '+cursorshape' feature?
    – Alex Kroll
    Commented May 24, 2015 at 1:29
  • Check terminal settings. And this question looks similar superuser.com/questions/634326/…
    – Alex Kroll
    Commented May 25, 2015 at 14:24
  • Which terminal emulator are you using? Have you tried something like let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1;BlinkingCursorEnabled=1\x7\<Esc>\\" and let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0;BlinkingCursorEnabled=0\x7\<Esc>\\"?
    – jjaderberg
    Commented May 25, 2015 at 20:11
  • @jjaderberg iTerm's escape sequence? Works only in iTerm with some cautions: iTerm Doc >iTerm2 supports several non-standard escape codes. These may not work properly in tmux or screen, and may have unknown effects on other terminal emulators. Proceed with caution.
    – Alex Kroll
    Commented May 26, 2015 at 5:47
  • 1
    I've check my soft one more time and all versions are same with yours but $TERM in mintty options is xterm-256color inside tmux screen-256color. tmux has version 1.9 (and your is 1.9a). I've launch vim inside tmux vim -u NULL (-u NULL means no config). Cursor shape is block in any mode, but when I assign t_SI and t_EI shape switch from block (normal mode) to I (insert mode) as expected. Can you try to launch vim with empty .vimrc, without any colorschemes and plugins?
    – Alex Kroll
    Commented May 26, 2015 at 21:49

2 Answers 2


It seems the problem is that tmux doesn't send your cursor-changing escape codes to the terminal emulator. You need to wrap your desired escape codes in a special sequence that tells tmux that it should pass it on to the outer terminal.

The sequence you need to wrap your escape sequence in is \<Esc>Ptmux;\<Esc> ... \<Esc>\\(Source). The ... is your escape sequence.

So, try doing something like this in your .vimrc:

if exists('$TMUX')
    let &t_SI = "\<Esc>Ptmux;\<Esc>\e[5 q\<Esc>\\"
    let &t_EI = "\<Esc>Ptmux;\<Esc>\e[2 q\<Esc>\\"
    let &t_SI = "\e[5 q"
    let &t_EI = "\e[2 q"

I don't use your terminal emulator or cygwin, so I couldn't test this code. But the method worked for me (I just wrapped other escape codes that suit my terminal).

  • This is even better - works without changing my .bashrc. Thank you.
    – Kossak
    Commented May 29, 2015 at 13:21

The correct value of $TERM environments variable is very important. Make sure that it is different from screen-256color. Set it to xterm-256color for example.

  • A cleaner solution than the accepted one.
    – mxgrn
    Commented Apr 8, 2023 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.