$ "cat"
^[[99;5u^[[118;5u^[[100;5u
Upon re-entering vim, either by starting a new instance or resuming the one in the background, the keys combos work again within vim, but are non-functional again when leaving it.
Key combinations still work after leaving vim.
9.0.993
Ubuntu 22/10
kitty 0.26.5
xterm-kitty
bash
No response
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Actually it's trivial to reproduce here, it just didn't occur to me what the key thing is that I've been doing. Simply running :! once is enough to mess up the terminal state for me. Tested used vim -u NONE
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Looks like my response didn't reach github:
Did you start Vim with "vim --clean"? If not, the do that.
This sounds like the t_TE termcap entry has been changed. To see the
relevant entries:
set t_TE t_TI t_RK
For me the result is correct:
t_TE=<1b>[>4;m<1b>[=0;1u
t_TI=<1b>[=1;1u
t_RK=<1b>[?u
It might be a problem related to a recent version of Kitty. It works fine in 0.21.2, the one that comes with Ubuntu 22.04.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
I tried with vim --clean, same result.
set t_TE t_TI t_RK
gives
t_TE=^[[>4;m^[[=0;1u
t_TI=^[[=1;1u
t_RK=^[[?u
Which at first glance seems equal to what you have.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Well, then I assume your Kitty version is broken.
It works fine for me, and I don't see any reason Vim would do differently for you.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
there two issues looks:
1, you can simply reproduce it by vim --clean -c ':!' -c ':call feedkeys("\<c-z>", "n")'
// but it is not only kitty, but xfce-term looks there stray chars also.
2, another one, ran manually as it:
a, vim --clean
b, :!<cr>
c, <c-z>
d, emit cat in bash cli
e, emit ctrl-c then there are some stray chars...
// this looks only happened at kitty vs but ok in xfce-term.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
perhaps you can use vim --log logfile.txt and check the raw key input: lines. (Not sure if this is the same as vim --clean -c 'call ch_logfile("logfile.txt")
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Thanks @chrisbra!
The (what I think) relevant part of the log for the execution of :! seems to be this (I've manually replaced control characters with their hex code like <1b>):
raw terminal output: "<1b>[?25l:!<1b>[?1004l<1b>[?2004l<1b>[?1l<1b>>"
raw terminal output: "<1b>[?25h<1b>[>4;m<1b>[=0;1u<1b>[?1049l" <<<<---- disable alternate screen
executing shell command:
raw terminal output: "<1b>[?1006l<1b>[?1002l"
closing channel log in the child process
closing logfile log
raw terminal output: "<1b>[>4;m<1b>[=0;1u<1b>[=1;1u" <<<<---- this seems broken?
raw terminal output: "<1b>[?1006h<1b>[?1002h"
raw terminal output: "<1b>]2;[No Name] - VIM<07>"
raw terminal output: "<1b>]1;[No Name]<07>"
raw terminal output: "<1b>[?1006l<1b>[?1002l"
looking for messages on channels
raw key input: "<0d>"
raw terminal output: "<1b>[?1006h<1b>[?1002h<1b>[?1049h<1b>[=1;1u<1b>[?1h<1b>=<1b>[?2004h<1b>[?1004h" <<<<---- enable alternate screen
It seems to me, that vim sends a t_TE, t_TI sequence while the alternate screen is still disabled.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Almost forgot: I've installed the kitty version that comes with Ubuntu, and the problem shows up there as well.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Now I am completely confused about what the problem is. There basically is mention of "reproduce it" without saying what "it" is. Some repro steps are for very different things and only confuse the actual problem being reported. I'll assume the actual problem is that the kitty keyboard protocol is enabled when it should not be.
I did finally manage to get Kitty in a state where, after using CTRL-Z in Vim it looks like it is still in a state with the Kitty keyboard protocol enabled, which the shell can't handle. Looking in the log I can see that Vim did send the code to disable the keyboard protocol. This points to Kitty not handling this properly. The code in the log is "<1b>[=0;1u", or "[=0;1u".
It does appear that using CTRL-Z without using ":!" before works fine. Once ":!" has been used the problem that the keyboard protocol is enabled appears. In the log I can see that what Vim sends for CTRL-Z is exactly the same in both cases. Thus this indicates there is state in Kitty that differs. I have no idea what state that is, AFAIK there should not be a difference.
@dotdash - Why do you mention the alternate screen? AFAIK the keyboard protocol has no relation with the alternate screen.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@dotdash - Why do you mention the alternate screen? AFAIK the keyboard protocol has no relation with the alternate screen.
I was looking at https://sw.kovidgoyal.net/kitty/keyboard-protocol/ which says:
Emit the escape code CSI > 1 u at application startup if using the main screen or when entering alternate screen mode, if using the alternate screen.
Which made me assume that the keyboard protocol setting is tied to the screen. I'm sorry for the confusion if that is not the case.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Further down on the page, there's also a note:
The main and alternate screens in the terminal emulator must maintain their own, independent, keyboard mode stacks. This is so that a program that uses the alternate screen such as an editor, can change the keyboard mode in the alternate screen only, without affecting the mode in the main screen or even knowing what that mode is. Without this, and if no stack is implemented for keyboard modes (such as in some legacy terminal emulators) the editor would have to somehow know what the keyboard mode of the main screen is and restore to that mode on exit.
So the keyboard protocol does indeed seem to be tied to the screen, and enabling the kitty keyboard protocol in the main screen is probably what's causing the issue.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Looking through that page searching for "alternate" reveals a note above "Disambiguate escape codes" that hints at there being a keyboard state for the alternate and main screen separately. It's mixed with the use of a "stack" (which is actually totally unreliable and therefore useless).
This is problematic, because Vim often has no clue about whether things happen in the main or the alternate screen. Even when started up it doesn't know where it is. And the user may switch between screens any time, especially when executing shell commands, without Vim being aware of it. There is a habit of using t_ti and t_te for switching between screens, but it's not set in stone and Vim doesn't (can't) parse termcap entries to find out what they are doing.
I'm not sure this can be solved.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Dont randomnly transition screens. There is no usecase for that. At startup always switch to alternate screen. Then enable the keyboard protocol. Whenever vim relinquishes control of the tty, whether that is to run a shell command, suspend itself, or quit, it is incumbent on it to restore the tty to the state it found it in, or if it is not capable of doing that, then to a known good state. Which means you turn off the keyboard protocol and preferably transition back to the main screen before relinquishing control of the tty.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Oh and as far as I can tell for this particular issue, all you need to do is emit the restore keyboard protocol bytes before you emit the switch to main screen bytes when doing :!
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
First of all: Vim runs in whatever screen is currently active. That cannot be changed, this is what has always happened and users depend on it.
It appears that the terminfo entry for xterm-kitty includes values for t_te and t_ti that switch to and from the alternate screen. I don't know why or where these entries come from, but they are an essential part of the problem. Vim doesn't parse the termcap entries (as if it could!) thus it has no clue that screen switching is happening. Note that there is no documentation for t_ti or t_te being used for screen switching. Terminfo mentions something about cursor positioning but that appears to be completely outdated.
Making assumptions that t_ti and t_te are indeed the termcap entries used for switching screens, there is an inconsistency between going in and out of termcap mode. In starttermcap() t_ti is output first, before t_TI. In stoptermcap() t_te was output after the other codes. This is kind of symmetric, but assuming (again) that switching between screens happens and it makes what follow work differently, then outputting t_te first would help. Thus asymmetry would be the goal, if you look at it this way.
I can indeed fix the specific problem by outputting t_te earlier. The big question is whether this causes problems in any other setup. It's impossible to predict. Breaking the symmetry is good in this situation, but might be bad in other situations, since we don't know what t_ti and t_te are being used for. I suppose the only way is to try and see who complains.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
FWIW, for now I'm working around the issue by having this in my vimrc:
set keyprotocol=xterm:mok2
let &term=&term
The second line is needed because keyprotocol only becomes effective when term is set.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
With patch 1063, running :!nano inside vim --clean no longer works properly, because the alternate screen stays in kitty keyboard protocol mode, and nano can't deal with that.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
case 1 still there, but can reduce the reproduce steps just to: vim --clean -c ':call feedkeys("\<c-z>", "n")'
// manually ran is ok (no issue if manually run)
would see some stray esc chars there after that, but this is not only kitty, but xfce-term (and with gnu-screen) also.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Please be specific about what the problem is. With the command you give I don't see any problem typing keys with modifiers. I do see some escape responses ending up in the shell, that is a completely different problem and doesn't belong in this issue.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
I have created #11719 with the command you gave.
That problem has been around for a while, but I don't think we had an issue for it.
I don't think there is a single fix, but we can try some things to make it happen less often, and discuss the progress on the issue.
Otherwise, I think after patch 9.0.1065 this issue should be fixed. Can we close it?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
options.txt;
*'restorescreen'* *'rs'* *'norestorescreen'* *'nors'*
'restorescreen' 'rs' boolean (default on)
global
{only in MS-Windows console version}
When set, the screen contents is restored when exiting Vim. This also
happens when executing external commands.
For non-Windows Vim: You can set or reset the 't_ti' and 't_te'
options in your .vimrc. To disable restoring:
set t_ti= t_te=
To enable restoring (for an xterm):
set t_ti=^[7^[[r^[[?47h t_te=^[[?47l^[8
(Where ^[ is an <Esc>, type CTRL-V <Esc> to insert it)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Closed #11705 as completed.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()