[vim/vim] arrow keys do not work on terminal with `tnoremap <Esc> <C-W>` (#2716)

66 views
Skip to first unread message

Pablo Bender

unread,
Mar 14, 2018, 10:28:43 PM3/14/18
to vim/vim, Subscribed

I want to enter in normal mode from terminal with as natural.
After map to exit from terminal mode with tnoremap <Esc> <C-W>N as described on termal.txt help, the arrow keys have stopped working (eg: arrow-up/down to navigate over shell command history).

Pressing arrow keys on terminal mode, I got the error: E21: Cannot make changes, 'modifiable' is off

steps to reproduce:
put tnoremap <Esc> <C-W>N on ~/.vimrc
open vim
open a terminal :terminal
execute a comand on terminal (eg: ls)
hit arrow-up to get the last executed command


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Bram Moolenaar

unread,
Mar 15, 2018, 4:49:31 PM3/15/18
to vim/vim, Subscribed

This is not a very good example. Typing arrow keys results in a sequence that starts with Esc.
I'll change it to:
tnoremap N
But you can make work:
tnoremap N
set notimeout ttimeout timeoutlen=100

Pablo Bender

unread,
Mar 15, 2018, 5:26:22 PM3/15/18
to vim/vim, Subscribed

I didn't know that arrow keys results in a sequence starting with esc.
It explains the problem.
I will try to find a comfortable map for me... however, the habit of hitting to escape from "typing mode" (insert-mode for common buffers or terminal-mode for terminal buffers) is very strong. It's a kind of muscle-memory.
thanks.

ThorodanBrom

unread,
Dec 7, 2018, 5:14:14 AM12/7/18
to vim/vim, Subscribed

This is not a very good example. Typing arrow keys results in a sequence that starts with Esc.
I'll change it to:
tnoremap N
But you can make work:
tnoremap N
set notimeout ttimeout timeoutlen=100

Is tnoremap N what we should use to make it work. Or did Markdown erase the rest of your suggestion @brammool ?
(If I type tnoremap <Esc> <C-W>N without backticks, it displays as follows : tnoremap N )

K.Takata

unread,
Dec 7, 2018, 6:27:48 AM12/7/18
to vim/vim, Subscribed

They are erased by markdown. The original comment was:

I'll change it to:
   tnoremap <F1> <C-W>N
But you can make <Esc> work:
   tnoremap <Esc> <C-W>N
   set notimeout ttimeout timeoutlen=100

ThorodanBrom

unread,
Dec 7, 2018, 6:48:07 AM12/7/18
to vim/vim, Subscribed

OK @k-takata . I noticed that the docs were changed to fix this, please ignore my PR #3674
However, the error still persists for me.
My .vimrc contains


tnoremap <Esc> <C-W>N
set notimeout ttimeout timeoutlen=100

Whenever, I press the arrow keys, it goes into terminal-normal mode.

FYI, I am using version 8.1.563 currently

K.Takata

unread,
Dec 10, 2018, 12:38:26 AM12/10/18
to vim/vim, Subscribed

Seeing the Bram's comment again, set notimeout ttimeout timeoutlen=100 looks incorrect.
It sets notimeout but also sets timeoutlen=100 (not ttimeoutlen=100).
However, setting ttimeoutlen=100 doesn't fix the problem, because all Esc are eaten by the mapping.

One idea is:

tnoremap <Esc> <C-W>N
tnoremap <Esc><Esc> <C-W>N
set timeout timeoutlen=1000  " Default
set ttimeout ttimeoutlen=100  " Set by defaults.vim

Cursor keys should work with this.
If Esc is typed once, Vim waits timeoutlen and goes to terminal-normal mode.
If Esc is typed twice, it goes to terminal-normal mode immediately.

ThorodanBrom

unread,
Dec 10, 2018, 5:28:08 AM12/10/18
to vim/vim, Subscribed

Double tapping the Esc key seems to be good enough - it's slightly annoying if you press Esc in term mode, and then get term-mode after a second. Would there be any issues/side-effects with timeoutlen=0 ?

Grégory Horion

unread,
May 29, 2019, 4:25:19 PM5/29/19
to vim/vim, Subscribed

i'm using iterm, and mapped to send vim special caracter \<C-W>N.
Works like a charm.
Screen Shot 2019-05-29 at 13 23 43

lacygoill

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

Possible duplicate of #2216.


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:40:20 AM6/6/20
to vim/vim, Subscribed

Mappings with are expected to only work in some situations. If they don't work, then don't use them. I'll add an extra note at the example for mapping in the terminal.


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:40:20 AM6/6/20
to vim/vim, Subscribed

Closed #2716.


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

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

Cheng JIANG

unread,
Dec 29, 2020, 12:13:52 PM12/29/20
to vim/vim, Subscribed

I'm wondering why neovim works with esc + arrow keys?


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:16:38 AM10/11/24
to vim/vim, Subscribed

Status here:

#2216 (comment)


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/2716/2407627002@github.com>

Reply all
Reply to author
Forward
0 new messages