Re: [vim/vim] [question] How to remap ctrl + Left/Right (Issue #9059)

24 views
Skip to first unread message

Gary Johnson

unread,
Oct 27, 2021, 4:20:03 PM10/27/21
to reply+ACY5DGGL33BYYDEFYX...@reply.github.com, vim...@googlegroups.com, vim...@googlegroups.com
On 2021-10-27, Julio Guerrero wrote:
> Hi Gary, I have applied those changes in my vimrc but the problem remains,
> after I ran the verbose command maps are pointing to my vimrc (same lines I
> added). I'm sorry I did not know this is the dev repo, will move my question to
> the other repo.
>
> Hi lacygoill, as per your questions:
>
> • $TERM: screen-256color
> • E846: Key code not set:
> • Ctrl-V then Ctrl-Right, delete lines
> • I use tmux
> • TERM out multiplexer: same as inside VIM - screen-256color

I'm using a different terminal now than I was this morning. Running
vim within tmux, I now see the problem.

In insert mode Ctrl-V Ctrl-Left inserts:

^[[1;5D

Ctrl-V Ctrl-Right inserts:

^[[1;5C

See

:help i_CTRL-V

Pressing Ctrl-Left in either normal or insert modes deletes the next
5 lines. Pressing Ctrl-Right also deletes 5 lines but goes to
insert mode.

That makes sense. Vim doesn't recognize those escape sequences so
it processes them as normal keystrokes. In normal mode, Vim ignores
that first <Esc> (^[). In insert mode, that first <Esc> puts Vim
into normal mode. Vim does not recognize the sequence [1 and
appears to ignore it. The ; will repeat the latest f, t, F or
T command. That may or may not move the cursor and affect the next
command. 5D deletes 5 lines. 5C deletes from the cursor to the end
of the line 4 more lines and starts insert mode.

I don't know the right solution at the moment, but a workaround
would be to put this in your vimrc.

if &term == "screen-256color"
nnoremap <Esc>[1;5C <C-Right>
nnoremap <Esc>[1;5D <C-Left>
inoremap <Esc>[1;5C <C-Right>
inoremap <Esc>[1;5D <C-Left>
endif

Regards,
Gary

mckel...@gmail.com

unread,
Nov 1, 2021, 10:34:16 PM11/1/21
to vim_use
Hi,

For xterm*,  you might be able to try these instead of a mapping that starts with <Esc>, since that can sometimes lead to messing with timeouts and/or having a delay when pressing <Esc> to leave insert mode etc.

  exec "set <xHome>=\e[1;*H"
  exec "set <xEnd>=\e[1;*F"
  exec "set <xUp>=\e[1;*A"
  exec "set <xDown>=\e[1;*B"
  exec "set <xRight>=\e[1;*C"
  exec "set <xLeft>=\e[1;*D"

thx,
-m
Reply all
Reply to author
Forward
0 new messages