I like to change the cursor shape when in insert mode, but I'm having trouble configuring this correctly when ssh-ing through tmux. Here are my findings:
- When I ssh outside of a local tmux session and I open Vim outside of a remote tmux session, cursor shape works (vertical bar in insert mode).
- When I ssh outside of a local tmux session and I open Vim inside a remote tmux session, cursor shape works.
- When I ssh inside of a local tmux session and I open Vim outside of a remote tmux session, cursor shape is broken (block in insert mode).
- When I ssh inside of a local tmux session and I open Vim inside a remote tmux session (nested tmux; my preferred setup), cursor shape is broken.
- When I open Vim locally inside of a local tmux session, cursorshape works (that is, something is going wrong with the combination of tmux and ssh; local tmux is fine locally).
My local machine is running OS X Sierra and my remote machine is CentOS 7. I think these are all the relevant dotfile settings, will post others if requested:
=== ~/.tmux.conf
(on both local and remote machines) ===
set-option -g default-terminal "screen-256color"
set-option -g xterm-keys on
=== ~/.vimrc
(on remote machine) ===
if empty($TMUX)
let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode
let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode
else
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
endif
if &term =~ '^screen'
" tmux will send xterm-style keys when its xterm-keys option is on
execute "set <xUp>=\e[1;*A"
execute "set <xDown>=\e[1;*B"
execute "set <xRight>=\e[1;*C"
execute "set <xLeft>=\e[1;*D"
endif
As a side note, cursor shape never seems to work with mosh, in any of these cases. I think this is a mosh limitation, but if someone has a way of getting it to work with mosh that would be especially helpful.