[vim/vim] Treat tmux like xterm so you get focused gained/lost events. (PR #9558)

92 views
Skip to first unread message

Doug Richardson

unread,
Jan 18, 2022, 4:29:27 PM1/18/22
to vim/vim, Subscribed

This change allows vim to get Focused Gained/Lost events when running with TERM set to tmux or tmux-256color. These values must be used under tmux per their FAQ:

PLEASE NOTE: most display problems are due to incorrect TERM! Before
reporting problems make SURE that TERM settings are correct inside and
outside tmux.

Inside tmux TERM must be "screen", "tmux" or similar (such as
"tmux-256color"). Don't bother reporting problems where it isn't!

Outside, it should match your terminal: particularly, use "rxvt" for rxvt
and derivatives.

Tested On

$ uname -a
Linux ip-172-16-0-117 5.10.0-10-cloud-amd64 #1 SMP Debian 5.10.84-1 (2021-12-08) x86_64 GNU/Linux

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/9558

Commit Summary

  • d36f176 Treat tmux like xterm so you get focused gained/lost events.

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/9558@github.com>

lacygoill

unread,
Jan 18, 2022, 4:53:18 PM1/18/22
to vim/vim, Subscribed

The issue is that it would make Vim treat any terminal as xterm-compatible as soon as we run tmux inside. Personally, I wouldn't mind, but I don't think this will be merged, because the outer terminal might not be xterm-compatible. I could be wrong though; we'll see.


Possible relevant issue: Allow overriding vim_is_xterm from an option at runtime.


In the meantime, you can get the focus events inside tmux, by adding these lines in your vimrc:

" Enable focus event tracking, see  :help xterm-focus-event
let &t_fe = "\<Esc>[?1004h"
let &t_fd = "\<Esc>[?1004l"
execute "set <FocusGained>=\<Esc>[I"
execute "set <FocusLost>=\<Esc>[O"

See :help tmux-integration.


I've always wondered whether in tmux (i.e. when $TMUX is not empty), Vim could internally start some kind of job to ask tmux the real name of the outer terminal:

$ tmux display-message -p '#{outer_terminal}'

Only upon receiving the answer, vim_is_xterm() would then be called.

Pseudo-code in Vim script:

vim9script
def OutCb(_, outer_terminal: string): bool
    if vim_is_xterm(outer_terminal)
        return true
    endif
    return false
enddef
job_start('tmux display-message -p #{client_termname}', {out_cb: OutCb})


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/9558/c1015867654@github.com>

Doug Richardson

unread,
Jan 18, 2022, 8:12:35 PM1/18/22
to vim/vim, Subscribed

In the meantime, you can get the focus events inside tmux, by adding these lines in your vimrc:

" Enable focus event tracking, see  :help xterm-focus-event
let &t_fe = "\<Esc>[?1004h"
let &t_fd = "\<Esc>[?1004l"
execute "set <FocusGained>=\<Esc>[I"
execute "set <FocusLost>=\<Esc>[O"

@lacygoill Thank you so much for this info! I guess the :help tmux-integration section is less than a year old, and I hadn't seen it before.

And you're right, the fix I proposed isn't completely general, since it assumes the outer terminal is xterm compatible.

Closing this PR.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/9558/c1015982312@github.com>

Doug Richardson

unread,
Jan 18, 2022, 8:12:41 PM1/18/22
to vim/vim, Subscribed

Closed #9558.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/9558/issue_event/5914401929@github.com>

Bram Moolenaar

unread,
Jan 19, 2022, 7:13:55 AM1/19/22
to vim/vim, Subscribed

tmux is a bit of a problem, since it is a layer on top of a terminal. We already have "screen.xterm", perhaps "tmux.xterm" would work too? I guess we might then also need to support other terminals after "tmux", such as "tmux.kterm".

What we really need is an overhaul of the whole termcap/terminfo mechanism.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/9558/c1016408717@github.com>

Reply all
Reply to author
Forward
0 new messages