Can't resize vim splits inside tmux

47

19

Everything is working fine outside of tmux. But in tmux I can't resize vim splits with the mouse. I have set mouse=a in my .vimrc. Is there a solution for this?

.tmux.conf:

$ cat ~/.tmux.conf
set-option -g mode-mouse on
set-option -g mouse-resize-pane on
set-option -g mouse-select-pane on
set-option -g mouse-select-window on

holms

Posted 2013-02-12T10:38:08.930

Reputation: 2 897

@romainl Hello! Resizing windows with default vim key bindings is fairly cumbersone IMHO. xD – trusktr – 2014-07-20T00:09:24.893

This is not a putty issue – jasonszhao – 2015-12-14T04:33:40.533

AFAIK this is a known/unresolved issue. Of course, if you drop your mouse in favor of your keyboard, this becomes pretty much a non-issue. – romainl – 2013-02-12T13:14:18.260

11Have you tried also setting ttymouse=xterm2 in Vim? That lets me drag around Vim splits inside tmux (it seems to default to xterm2 when run with TERM=xterm, which is probably the case outside of tmux). – Chris Johnsen – 2013-02-13T06:51:31.617

@ChrisJohnsen it works!! please post this comment as an answer and I'll accept it :) – holms – 2013-02-13T07:50:39.260

Answers

69

It appears that dragging the status line to resize a split is not possible when the Vim option ttymouse is xterm; it does work when the value is xterm2 though. The latter value configures Vim to ask for an extended mouse reporting mode that (among other things) provides better dragging support. This extended mode only works with newer versions of xterm (and other compatible terminal emulators, including tmux), so it is not the default value.

You could use something like the following in your .vimrc to set the option:

set mouse+=a
if &term =~ '^screen'
    " tmux knows the extended mouse mode
    set ttymouse=xterm2
endif

(Though, I am not sure how this will affect actual screen instances, which also use a TERM that starts with screen.)

When you are outside of tmux, the TERM environment variable is probably an xterm-ish value, and Vim will probe for the xterm version by using the t_RV control sequence.

Chris Johnsen

Posted 2013-02-12T10:38:08.930

Reputation: 31 786

1the condition does not become true in my Tmux, but simply setting the variable works. – jasonszhao – 2015-12-14T04:38:46.497

1If you work in a terminal which has over 223 columns, you will need to set ttymouse to sgr as xterm2 doesn't go beyond that. You can check if your vim supports sgr with has("mouse_sgr"). It should always be safe to set sgr instead of xterm2 because it is backwards compatible. See :help ttymouse – Sudo Bash – 2019-04-16T00:36:35.237

3You mention not knowing how this will affect screen (as opposed to tmux). The answer is: screen has the same problem, and this exact fix works there as well. – Moss Collum – 2013-12-03T20:01:04.270

14

In my case it resolved both cases: mouse split resize and mouse position problem for wide screen.

The fix is:

if has("mouse_sgr")
    set ttymouse=sgr
else
    set ttymouse=xterm2
end

tojocky

Posted 2013-02-12T10:38:08.930

Reputation: 141

This worked for me. – Paul Brannan – 2017-09-14T14:29:47.833