Add ttymouse=xterm support when TERM=tmux

58 views
Skip to first unread message

Michael Henry

unread,
Sep 29, 2016, 7:05:37 AM9/29/16
to vim...@googlegroups.com
All,

Vim has compiled-in knowledge of a few terminals whose mouse
support is like that of xterm. One such terminal is GNU screen.
Missing from this list is tmux, a terminal multiplexer similar
to GNU screen:
https://tmux.github.io/

When ``$TERM`` is ``screen``, Vim automatically performs the
equivalent of ``:set ttymouse=xterm``; when ``$TERM`` is
``tmux``, ``ttymouse`` is left unset which causes the following
incorrect mouse-related settings to be set:

<DecMouse> ^[[
<NetMouse> ^[}
<Mouse> ^[MG

<DecMouse> in particular interferes with the processing of
key codes that start with ``^[[``.

I'd like to propose the below patch which adds supports for tmux
in the same way that Vim currently supports screen.

diff --git a/src/os_unix.c b/src/os_unix.c
index 5f1c487..f12e944 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -2261,6 +2261,7 @@ use_xterm_like_mouse(char_u *name)
return (name != NULL
&& (term_is_xterm
|| STRNICMP(name, "screen", 6) == 0
+ || STRNICMP(name, "tmux", 4) == 0
|| STRICMP(name, "st") == 0
|| STRNICMP(name, "st-", 3) == 0
|| STRNICMP(name, "stterm", 6) == 0));

Thanks,
Michael Henry

Christian Brabandt

unread,
Sep 29, 2016, 7:12:21 AM9/29/16
to vim...@googlegroups.com
I thought, tmux proposed to use the screen terminal entry?

Best,
Christian
--
Letzte Worte eines Sportschützen:
"Da klemmt doch was am Abzug."

James McCoy

unread,
Sep 29, 2016, 7:34:08 AM9/29/16
to vim_dev

On Sep 29, 2016 7:12 AM, "Christian Brabandt" <cbl...@256bit.org> wrote:
> I thought, tmux proposed to use the screen terminal entry?

Staying in 2.1 tmux can be used to differentiate functionality.

https://github.com/tmux/tmux/blob/20598dff258da1e96a060adba95e8e05bfdd8b3b/FAQ#L355-L378

Cheers,
James

Michael Henry

unread,
Sep 30, 2016, 8:02:45 AM9/30/16
to vim...@googlegroups.com
Yes, the difference between the ``screen`` and ``tmux`` termcap
entries is how they deal with italics and reverse-mode video.
That's the motivation for setting ``TERM=tmux``, as GNU screen
doesn't support italics and the terminfo for ``TERM=screen`` is
incorrect for use with tmux:

$ infocmp screen tmux
comparing screen to tmux.
comparing booleans.
comparing numbers.
ncv: NULL, NULL.
comparing strings.
ritm: NULL, '\E[23m'.
rmso: '\E[23m', '\E[27m'.
sitm: NULL, '\E[3m'.
smso: '\E[3m', '\E[7m'.

Most Vim functionality works correctly with ``TERM=tmux``, but
the mouse is detected incorrectly. It works for ``TERM=screen``
because of the special-case checks for ``screen`` (among others)
in Vim's ``use_xterm_like_mouse()`` function.

At present it appears that hard-coding knowledge of certain
terminals into Vim's source is the solution for determining the
correct mouse protocol, which is why I proposed adding support
for tmux in the above function. Is there a different way Vim
should be detecting the mouse protocol?

Michael Henry

Reply all
Reply to author
Forward
0 new messages