映射<esc>在 vimrc 中导致奇怪的箭头行为 [英] Mapping <esc> in vimrc causes bizarre arrow behaviour

查看:33
本文介绍了映射<esc>在 vimrc 中导致奇怪的箭头行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个快乐的 VIM 用户,尽管我承认我还远远不够流利.我发现了这个不错的帖子:Vim 清除上次搜索突出显示,我想如果我不这样做我会成为一个更好的人不必每次搜索时都敲打随机字符序列.现在,我也在使用这里的 vimrc 配置:

I am a happy VIM user, although I admit I'm quite far from being fluent. I found this nice post: Vim clear last search highlighting and I thought I'd become a better person if I didn't have to hammer away a random character sequence every time I did a search. Now, I'm also using the vimrc config from here:

http://amix.dk/vim/vimrc.html

而我遇到的问题是,当我添加行 nnoremap <esc>:noh<return><esc> 到它(它似乎没有区别我把它放在哪里)当我在命令模式下使用箭头时,我会遇到尴尬的行为,即从 A 到 D 的字母出现在换行,我切换到插入模式.

and the problem I have is that when I add the line nnoremap <esc> :noh<return><esc> to it (it doesn't seem to make a difference where I put it) I get awkward behaviour when I use arrows in command mode, namely letters from A to D appear in a newline and I get switched to insert mode.

肯定有一些映射冲突,但对于我的生活,我无法弄清楚它在哪里.

There has to be some mapping conflict but for the life of me I can't figure out where it is.

根据答案,最终 vimrc 部分不相关,提到的 nnoremap 命令会导致改变的箭头行为,即使它是唯一的vimrc 入口.将标题更改为内容更丰富的标题.

As it follows from the answers it turns out the Ultimate vimrc part is not relevant, the mentioned nnoremap command will cause altered arrow behaviour even if it's the only vimrc entry. Changing title to a more informative one.

附注.我知道我不应该使用箭头,希望有一天我能到达那里.

PS. I know I shouldn't use arrows, hopefully I'll get there one day.

推荐答案

映射

nnoremap <esc> :noh<return><esc>

会与所谓的灰键"冲突;我相信它应该只在 GVim 中使用,或者由不使用箭头等特殊键的人在终端 Vim 中使用.

will conflict with so called "grey keys" and I believe that it should be used either in GVim only or in terminal Vim by someone who does not use special keys like arrows.

据我所知(和猜测)Vim 是如何处理键的,我想说这是不可能做任何事情的.为了让 Vim 识别特殊键,它的所有组件都应该排成一行,所以当你按下 Arrow Left 时,Vim 得到以下代码序列:

From what I know (and guess) how Vim processes keys, I would say that it's impossible to do anything with this. For Vim to recognize special key all its components should go in a row, so when you press Arrow Left Vim gets the following sequence of codes:

[ D

但是在您映射后 Arrow Left 变为:

But after your mapping Arrow Left becomes:

: n o h l

[ D

Vim 看到两个独立的序列,并将 视为一次按 Escape 键,因此接下来的两个代码是 左箭头键失去了它们的特殊意义.

Vim sees two separate sequences and treats <esc> as a single press of Escape key, thus next two codes of Left Arrow key lose their special meaning.

所以我建议你将 :noh 映射到其他一些键序列(例如,映射到以 开头的序列,参见 :help mapleadercode>; 我不建议你使用 F 键,使用它们和使用箭头键一样糟糕).

So I suggest you to map :noh to some other key sequence (e.g. to one starting with <leader>, see :help mapleader; I don't recommend you to use F-keys, using them is as bad as using of arrow keys).

这篇关于映射&lt;esc&gt;在 vimrc 中导致奇怪的箭头行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆