Disabling arrow key in insert mode

483 views
Skip to first unread message

Thomas R.

unread,
May 13, 2016, 6:19:15 AM5/13/16
to vim_use
Hello,

I'm trying to disable the arrow keys in insert mode. I added the following in my vimrc:

inoremap <Left> <Esc>
inoremap <Right> <Esc>
inoremap <Up> <Esc>
inoremap <Down> <Esc>
inoremap <PageUp> <Esc>
inoremap <PageDown> <Esc>

When I'm in insert mode, I now can't navigate left and right.
However, and I press up or down, the cursor still moves and I can still navigate.

Any idea how that could be?

Thank you

Tony Mechelynck

unread,
May 13, 2016, 8:14:50 PM5/13/16
to vim...@googlegroups.com, Thomas R.
Try using <Nop> instead of <Esc> as the {rhs} of your mappings.
See :help <Nop>

The above mappings would all put you back in Normal mode, where
additional arrow presses would work.

This said, why do you want to disable arrow keys in Insert mode? Since
hjkl insert characters then, you would have to escape back to Normal
mode (either by <Esc>, do something, a or by Ctrl-O to do one
Normal-mode command), or to use the mouse, whenever you really want to
move the cursor. It regularly happens to me to notice that I made a
typo earlier in the current word, and then the easiest way to go back
and correct is by means of the arrow keys.


Best regards,
Tony.

Thomas R.

unread,
May 13, 2016, 8:35:10 PM5/13/16
to vim_use, thomas....@gmail.com
Hello, Thank you for the answer. I use this to force myself not to use the arrow key.

I tried using <Nop> but the behavior is the same: I can still go up and down.

Here is the whole part of my .vimrc that deals with arrow keys:

nnoremap <Left> <Esc>
nnoremap <Right> <Esc>
nnoremap <Up> <Esc>
nnoremap <Down> <Esc>
nnoremap <PageUp> <Esc>
nnoremap <PageDown> <Esc>

inoremap <Left> <Esc>
inoremap <Right> <Esc>
inoremap <Up> <Esc>
inoremap <Down> <Esc>
inoremap <PageUp> <Esc>
inoremap <PageDown> <Esc>

vnoremap <Left> <Esc>
vnoremap <Right> <Esc>
vnoremap <Up> <Esc>
vnoremap <Down> <Esc>
vnoremap <PageUp> <Esc>
vnoremap <PageDown> <Esc>

Could it be that a plugin reactivates them? If yes is there a way to test if a key has been remaped?

Thank you

Thomas R.

unread,
May 13, 2016, 8:40:04 PM5/13/16
to vim_use, thomas....@gmail.com
I found the culprit, I use YouCompleteMe and this plugin remaps the <Up> key as I found out here:

i <Up> * pumvisible() ? "\<C-P>" : "\<Up>"
Last set from ~/.vim/bundle/YouCompleteMe/autoload/youcompleteme.vim

If anyone has an idea on how to bypass that...


Tuấn Trần

unread,
Aug 20, 2016, 2:44:42 AM8/20/16
to vim_use, thomas....@gmail.com
Hi Thomas,
I have same problem. Each time I press <Up> or <Down> key in Insert Mode, I always get * pumvisible() ? "\<C-P>" : "\<Up>".
I searched and found that problem comes from vim-autoclose plugin, not YouCompleteMe. You can see here:
https://github.com/Townk/vim-autoclose/issues/3

This config saves my day :D. If you use AutoClose plugin, you should add this line to your .vimrc file

if !has("gui_running")
let g:AutoClosePreservDotReg = 0
endif

Hope it help!
Reply all
Reply to author
Forward
0 new messages