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

7 views
Skip to first unread message

Julio Guerrero

unread,
Oct 27, 2021, 11:04:26 AM10/27/21
to vim/vim, Subscribed

Steps to reproduce

Hi there,

I love vim and admire all the job done here. I have tried all in stackoverflow and other blogs without success. Ctrl + Right/Left is creating a lot issues on my developments it deletes lines and I have spent a lot of time fixing those changes , so I want to block this shortcut is not helping me. Would anybody please help me with this ?

Thanks in advance.

Regards,
Julio

Expected behaviour

stop deleting lines

Operating system

ubuntu 20

Version of Vim

8.1

Logs and stack traces

none


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

Gary Johnson

unread,
Oct 27, 2021, 12:27:47 PM10/27/21
to reply+ACY5DGDTFU4ET4E532...@reply.github.com, vim...@googlegroups.com
On 2021-10-27, Julio Guerrero wrote:

> I love vim and admire all the job done here. I have tried all in stackoverflow
> and other blogs without success. Ctrl + Right/Left is creating a lot issues on
> my developments it deletes lines and I have spent a lot of time fixing those
> changes , so I want to block this shortcut is not helping me. Would anybody
> please help me with this ?

How you fix it depends on what's causing it and whether you
experience this in normal mode or in insert mode. According to the
:help entries, Ctrl + Right/Left shouldn't do that; they should move
the cursor to the right or left by words.

:help <C-Right>
[count] WORDS forward. |exclusive| motion.

:help <C-Left>
[count] WORDS backward. |exclusive| motion.

:help i_<C-Right>
cursor one word forward (like "w" command)

:help i_<C-Left>
cursor one word back (like "b" command)

If those are the commands giving you problems, you can fix that by
mapping them to <Nop>, like this:

nmap <C-Right> <Nop>
nmap <C-Left> <Nop>
imap <C-Right> <Nop>
imap <C-Left> <Nop>

See also:

:help <Nop>
:help 05.4
:help map-commands

Those keys may instead have been remapped by one of your plugins.
You can check that by executing the following:

:verbose map <C-Right>
:verbose map <C-Left>
:verbose imap <C-Right>
:verbose imap <C-Left>

If any of those commands show you where those keys have been
remapped, you can check the documentation for that plugin to find
out how to disable them.

If none of that helps, come back here with what you tried and what
the results were and we can go from there.

One last thing. This is the Vim development list, vim_dev, which is
intended for reporting bugs and feature requests, not problems with
using Vim. For questions like yours, it is preferred that you use
the Vim user list, vim_use.

Regards,
Gary

vim-dev ML

unread,
Oct 27, 2021, 12:28:08 PM10/27/21
to vim/vim, vim-dev ML, Your activity

On 2021-10-27, Julio Guerrero wrote:

> I love vim and admire all the job done here. I have tried all in stackoverflow
> and other blogs without success. Ctrl + Right/Left is creating a lot issues on
> my developments it deletes lines and I have spent a lot of time fixing those
> changes , so I want to block this shortcut is not helping me. Would anybody
> please help me with this ?

lacygoill

unread,
Oct 27, 2021, 1:21:43 PM10/27/21
to vim/vim, vim-dev ML, Comment

Which terminal are you using?
What's the output of echo $TERM in the shell?
What's the output of :set <xRight>? in Vim?
In insert mode, if you press CTRL-V then CTRL-Right, what is inserted in the buffer?
Do you use a terminal multiplexer? If so, which one? And what is the output of echo $TERM outside as well as inside this terminal multiplexer?


You are receiving this because you commented.

Julio Guerrero

unread,
Oct 27, 2021, 3:02:19 PM10/27/21
to vim/vim, vim-dev ML, Comment

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


You are receiving this because you commented.

lacygoill

unread,
Oct 27, 2021, 3:10:14 PM10/27/21
to vim/vim, vim-dev ML, Comment

E846: Key code not set:

Try to add this into your vimrc:

if &term =~ '^\%(screen\|tmux\)'
    " Enable modified arrow keys, see  :help xterm-modifier-keys
    execute "silent! set <xUp>=\<Esc>[@;*A"
    execute "silent! set <xDown>=\<Esc>[@;*B"
    execute "silent! set <xRight>=\<Esc>[@;*C"
    execute "silent! set <xLeft>=\<Esc>[@;*D"
endif

Make sure that :echo &term contains either the string screen or tmux when you start Vim from inside tmux.

Ctrl-V then Ctrl-Right, delete lines

I doubt it does that if you are in insert mode. You probably pressed the keys from normal mode. Try again from insert mode (or from command-line mode).

I use tmux

See :help tmux-integration.

TERM out multiplexer: same as inside VIM - screen-256color

If $TERM is the same inside and outside tmux, then that's wrong. Outside, it should identify the real terminal (e.g. xterm-256color). Inside, it should identify screen or tmux.


You are receiving this because you commented.

Gary Johnson

unread,
Oct 27, 2021, 4:20:01 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

vim-dev ML

unread,
Oct 27, 2021, 4:20:20 PM10/27/21
to vim/vim, vim-dev ML, Your activity

Julio Guerrero

unread,
Oct 27, 2021, 6:00:31 PM10/27/21
to vim/vim, vim-dev ML, Comment

Thank you all! Yes that condition fixed my problem! what an awesome support!


You are receiving this because you commented.

Julio Guerrero

unread,
Oct 27, 2021, 6:00:32 PM10/27/21
to vim/vim, vim-dev ML, Comment

Closed #9059.


You are receiving this because you commented.

Reply all
Reply to author
Forward
0 new messages