As suggested in the docs, I added the following map in my vimrc:
tnoremap <Esc> <C-\><C-N>
The mapping works as said. However, now whenever I try to go up or down the history in the terminal buffer (using the arrow keys), an E21 is thrown. Disabling the map solves the issue.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
On my machine, up and down produce the sequence of keycodes Esc O A and Esc O B. So, when you press one of these arrows, maybe Vim interprets Esc as a command to go to Terminal-Normal mode, and from there, it may interpret O as a command to open a new line above the current one, which is forbidden since the buffer is non-modifiable.
I noticed a similar issue. With the mapping you mentioned in your post, all the readline key bindings whose prefix is Alt do not work as expected. For example, Alt-b should move the cursor one word backward, while staying in Terminal-Job mode. But with the mapping, it moves back one word and switch to Terminal-Normal mode.
Because of this, you can't navigate across the different words on the command-line with M-b and M-f, like you could in a terminal outside Vim, because as soon as you press M-b, you aren't in Terminal-Job mode anymore.
So far, I haven't found a solution, so I just use 2 Escape in the lhs of the mapping:
tnoremap <esc><esc> <c-\><c-n>
Hi @lacygoill,
Thanks for the explanation. In fact, I like the mapping in your workaround (two ESCs) more than the previous one 👍
I have ttimeout set to 50.
I can confirm the same issue here. If I :tnoremap <Esc> <C-\><C-N>, then the arrow keys or any other key that sends an escape sequence starting with <Esc> no longer gets passed through to the terminal.
I have ttimeoutlen=100.
So what terminal are you using?
GNOME Terminal 3.30.0 using VTE 0.54.0
Mapping is expected to cause problems. It may work in some specific situations (e.g. in the GUI), but it if fails then just don't use it. It's not something that can be fixed in Vim.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Closed #2216.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
My experience with this is.
This workaround works for vim 8.x (Ubuntu 20.04 and 22.04):
tnoremap <esc> <c-\><c-n>
tnoremap <esc>: <c-\><c-n>:
whereas this:
tnoremap <esc> <c-\><c-n>
works without problems on vim 9.1 (Ubuntu 24.04).
The ability to map this key is ergonomically very interesting.
Thank you @lacygoill for posting this workaround!
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()