Steps to reproduce
Open a gnome terminal, and run this shell command:
TERM=gnome vim -Nu NONE -S <(cat <<'EOF'
vim9script
execute "set t_fe=\<Esc>[?1004h"
execute "set t_fd=\<Esc>[?1004l"
echoraw(&t_fe)
autocmd FocusLost * echomsg 'FocusLost is fired'
&ttimeoutlen = 100
EOF
)
E349 is given:
E349: No identifier under cursor
Focus a different window (e.g. web browser), then focus back the Vim terminal window.
E349 is given a second time:
E349: No identifier under cursor
Expected behavior
No error is given. This message is echo'ed:
FocusLost is fired
Because according to :help xterm-focus-event, setting 't_fe' and 't_fd' is all that is needed to enable the focus event tracking feature:
If your terminal does support this but Vim does not recognize the terminal,
you may have to set the options yourself: >
let &t_fe = "<Esc>[?1004h"
let &t_fd = "<Esc>[?1004l"
Operating system
Ubuntu 20.04.3 LTS
Version of Vim
8.2 Included patches: 1-3757
Additional Context
The issue can be fixed by setting <FocusGained> and <FocusLost>:
TERM=gnome vim -Nu NONE -S <(cat <<'EOF'
vim9script
execute "set t_fe=\<Esc>[?1004h"
execute "set t_fd=\<Esc>[?1004l"
execute "set <FocusGained>=\<Esc>[I"
execute "set <FocusLost>=\<Esc>[O"
echoraw(&t_fe)
autocmd FocusLost * echomsg 'FocusLost is fired'
&ttimeoutlen = 100
EOF
)
There are 2 possibilities:
't_fe', <FocusGained> and <FocusLost> should be automatically set as well't_fe' and 't_fd' is not enough; they also have to set <FocusGained> and <FocusLost>IMO, it's a bug. Vim should be able to set <FocusGained> and <FocusLost> automatically.
For example, that's what it does for 'ttymouse':
vim -Nu NONE -S <(cat <<'EOF'
vim9script
&term = 'xterm-256color'
execute('set! termcap')->split('\n')->writefile('/tmp/termcap1.log')
&ttymouse = 'sgr'
execute('set! termcap')->split('\n')->writefile('/tmp/termcap2.log')
edit /tmp/termcap1.log
split /tmp/termcap2.log
windo diffthis
EOF
)
In the upper window, notice how Vim automatically set <SgrMouse> and <SgrMouseRelease> when we set 'ttymouse' to sgr:
<SgrMouseRelease> ^[[<*m
<SgrMouse> ^[[<*M
Why can't Vim do the same when we set 't_fe'?
If this is not a bug, then at least the documentation should be updated. As a suggestion, here is a patch:
diff --git a/runtime/doc/term.txt b/runtime/doc/term.txt index 3333a3ab6..bc42233bb 100644 --- a/runtime/doc/term.txt +++ b/runtime/doc/term.txt @@ -150,12 +150,14 @@ terminal that tmux is running in): > " 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" " Enable modified arrow keys, see :help arrow_modifiers - execute "silent! set <xUp>=\<Esc>[@;*A" - execute "silent! set <xDown>=\<Esc>[@;*B" - execute "silent! set <xRight>=\<Esc>[@;*C" - execute "silent! set <xLeft>=\<Esc>[@;*D" + execute "set <xUp>=\<Esc>[@;*A" + execute "set <xDown>=\<Esc>[@;*B" + execute "set <xRight>=\<Esc>[@;*C" + execute "set <xLeft>=\<Esc>[@;*D" endif < *cs7-problem* @@ -606,6 +608,8 @@ If your terminal does support this but Vim does not recognize the terminal, you may have to set the options yourself: > let &t_fe = "\<Esc>[?1004h" let &t_fd = "\<Esc>[?1004l" + execute "set <FocusGained>=\<Esc>[I" + execute "set <FocusLost>=\<Esc>[O" If this causes garbage to show when Vim starts up then it doesn't work. *termcap-colors*
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
![]()
We should update the help to mention setting <FocusGained> and <FocusLost>.
The use_xterm_like_mouse() checks for "screen", "tmux", "stterm". Perhaps it should also check for "gnome"?
Is $TERM usually just "gnome" or could there be an addition?
I side effect is that 'ttymouse' will default to "xterm". Is that OK?
The use_xterm_like_mouse() checks for "screen", "tmux", "stterm". Perhaps it should also check for "gnome"?
I used gnome because I suppose it's the default terminal on Ubuntu. But the same issue probably applies to Konsole, xfce, and other popular terminals. I need to do more tests to be sure, but I suspect the suggested settings would work in all popular terminals.
I don't know why there is a link between the focus event tracking feature and the mouse codes. Maybe the code should handle both features in separate functions?
Is $TERM usually just "gnome" or could there be an addition?
Here is the list of all terminal names mathing "gnome" on my machine:
$ toe -as | grep gnome
*-----+-: gnome GNOME Terminal
*-----+-: gnome+pcfkeys VTE's variation on xterm+pcfkeys
*-----+-: gnome-2007 GNOME Terminal snapshot 2.18.1
*-----+-: gnome-2008 GNOME Terminal snapshot 2.22.3
*-----+-: gnome-2012 GNOME Terminal 3.6.0
*-----+-: gnome-256color GNOME Terminal with xterm 256-colors
*-----+-: gnome-fc5 GNOME Terminal
*-----*-: gnome-rh62 Gnome terminal
*-----*-: gnome-rh72 GNOME Terminal
*-----+-: gnome-rh80 GNOME Terminal
*-----+-: gnome-rh90 GNOME Terminal
*-----+-: screen-bce.gnome screen optimized for GNOME-Terminal
*-----+-: screen.gnome screen in GNOME Terminal
A side effect is that 'ttymouse' will default to "xterm". Is that OK?
In gnome-terminal and xfce4-terminal, the default value is empty. Switching to xterm should be OK, but I would need to make more tests to be sure.
I don't anticipate it will cause problems, let's just recognize gnome and see if someone has a problem with it.
Closed #9296.
—
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.![]()
fixed by 48873ae
—
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.![]()