How do I disable the arrow keys in insert mode?

I have the following lines in my .vimrc, which I thought would be more than sufficient:

nnoremap <left> <nop>
nnoremap <right> <nop>
nnoremap <up> <nop>
nnoremap <down> <nop>

inoremap <left> <nop>
inoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>

The arrow keys don't do anything (as expected) in normal mode, but continue to function in insert mode. I've also tried imap and that doesn't work either. Querying the mapping with inoremap <left> confirms that the binding isn't getting overwritten by something else. I'm not sure what's going on.

As one last test, I started up vim with no vimrc with vim -u NONE , then only ran the mappings. If I enter insert mode and hit an arrow key now, it inserts the letters A, B, C or D on a new line where my cursor is, which is completely not what I was expecting.


Based on this page, you can do it with the following mappings.

 noremap  <Up> ""
 noremap! <Up> <Esc>
 noremap  <Down> ""
 noremap! <Down> <Esc>
 noremap  <Left> ""
 noremap! <Left> <Esc>
 noremap  <Right> ""
 noremap! <Right> <Esc>

I tested them and they work, but I do not currently understand why this magic works.

In particular, I am not sure why it is necessary to map twice, but it should be effective for solving your problem.


That insertion of ABCD rings a bell. You seem to have the problem described in Fix broken arrow key navigation in insert mode and Fix arrow keys that display ABCD on remote shell, and possibly a workaround implemented.

That interferes with the :imap s to <Nop> .

链接地址: http://www.djcxy.com/p/78866.html

上一篇: 使用GraphicsEnvironment取消注册字体?

下一篇: 如何在插入模式下禁用箭头键?