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 May 24 '15 at 1:29
  • Check terminal settings. And this question looks similar superuser.com/questions/634326/… – Alex Kroll May 25 '15 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 May 25 '15 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 May 26 '15 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 May 26 '15 at 21:49
up vote 10 down vote accepted

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>\\"
else
    let &t_SI = "\e[5 q"
    let &t_EI = "\e[2 q"
endif

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 May 29 '15 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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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