[vim/vim] Mapping <Esc> to CTRL-\_CTRL-N makes terminal non-modifiable (#2216)

182 views
Skip to first unread message

Manas Thakur

unread,
Oct 18, 2017, 7:00:46 AM10/18/17
to vim/vim, Subscribed

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

lacygoill

unread,
Oct 18, 2017, 7:56:44 AM10/18/17
to vim/vim, Subscribed

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>

Manas Thakur

unread,
Oct 18, 2017, 8:38:16 AM10/18/17
to vim/vim, Subscribed

Hi @lacygoill,

Thanks for the explanation. In fact, I like the mapping in your workaround (two ESCs) more than the previous one 👍

Bram Moolenaar

unread,
Oct 19, 2017, 9:03:01 AM10/19/17
to vim/vim, Subscribed

Manas Thakur wrote:

> As suggested in the docs, I added the following map in my vimrc:
> ```vim

> 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.

Works for me. Check your settings, is 'timeout' set and otherwise
'ttimeout' set?

--
[clop clop]
MORTICIAN: Who's that then?
CUSTOMER: I don't know.
MORTICIAN: Must be a king.
CUSTOMER: Why?
MORTICIAN: He hasn't got shit all over him.
The Quest for the Holy Grail (Monty Python)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Manas Thakur

unread,
Oct 21, 2017, 5:47:45 AM10/21/17
to vim/vim, Subscribed

I have ttimeout set to 50.

Josh Triplett

unread,
Sep 9, 2018, 9:57:55 PM9/9/18
to vim/vim, Subscribed

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.

Christian Brabandt

unread,
Sep 10, 2018, 4:14:26 AM9/10/18
to vim/vim, Subscribed

So what terminal are you using?

h_east

unread,
Sep 10, 2018, 5:04:15 AM9/10/18
to vim_dev
Hi,

2018-9-10(Mon) 17:14:26 UTC+9 Christian Brabandt:
> So what terminal are you using?

I can reproduce it too.

Vim 8.1.0359 on Ubuntu 18.04
I am using GNOME treminal 3.28.2 (VTE 0.52.2) or PuTTY 0.70.
Both are using with "TERM=xterm-256color"

How to reproduce:
- Start Vim with terminal mapping
$ vim --clean +"tnoremap <Esc> <C-\><C-N>"
- Open terminal window.
:term
- Input a Left arrow key.


Expected behavior:
- Nothing happens.

Actual behavior:
- Goto Terminal-Normal mode
- E21 error occurs.
E21: Cannot make changes, 'modifiable' is off


NOTE:
Similar things happen in insert mode.
- Start Vim with terminal mapping
$ vim --clean +"inoremap <Esc> <C-\><C-N>"
- Goto insert mode.
i
- Input a Left arrow key.


Expected behavior:
- Nothing happens.

Actual behavior:
- 'D' was inputed.

--
Best regards,
Hirohito Higashi (h_east)

Josh Triplett

unread,
Sep 10, 2018, 8:30:56 AM9/10/18
to vim/vim, Subscribed

GNOME Terminal 3.30.0 using VTE 0.54.0

Bram Moolenaar

unread,
Jun 6, 2020, 9:38:35 AM6/6/20
to vim/vim, Subscribed

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.

Bram Moolenaar

unread,
Jun 6, 2020, 9:38:38 AM6/6/20
to vim/vim, Subscribed

Closed #2216.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub, or unsubscribe.

Gustavo Homem

unread,
Oct 11, 2024, 11:15:31 AM10/11/24
to vim/vim, Subscribed

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.Message ID: <vim/vim/issues/2216/2407624950@github.com>

Reply all
Reply to author
Forward
0 new messages