macos 箭头键输入大写字母而不是移动光标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4303830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:23:22  来源:igfitidea点击:

Arrow keys type capital letters instead of moving the cursor

macosterminalvim

提问by Allen Bargi

I've installed the latest vim using homebrew and also installed mac-vim from the google code homepage. in mac-vim everything works fine. but when I run vim in terminal.app in mac and go to insert mode I'll get A B C D for arrow keys which is extremely annoying.

我已经使用自制软件安装了最新的 vim,还从谷歌代码主页安装了 mac-vim。在 mac-vim 中一切正常。但是当我在 mac 中的 terminal.app 中运行 vim 并进入插入模式时,我将获得箭头键的 ABCD,这非常烦人。

I googled it and tried all the solutions but nothing is working for me!

我用谷歌搜索并尝试了所有解决方案,但没有任何效果对我有用!

it gets intresting when I run vim with vim -u NONE -U NONE -Nthen the arrow keys start to function normally in insert mode.

当我运行 vim 时它变得有趣,vim -u NONE -U NONE -N然后箭头键开始在插入模式下正常工作。

my vimrc files are a clone of janus (from carlhuda)

我的 vimrc 文件是janus的克隆(来自 carlhuda)

do you have the same problem in terminal? is there a way to fix it in terminal.app?

你在终端有同样的问题吗?有没有办法在 terminal.app 中修复它?

回答by devsathish

Just create an empty ".vimrc file in the home directory of the remote machine. It started working fine for me.

只需在远程机器的主目录中创建一个空的“.vimrc 文件。它对我来说开始工作正常。

touch ~/.vimrc

回答by AMing

You need to set no compatible mode in the vim Try following command in normal mode

您需要在 vim 中不设置兼容模式 尝试在正常模式下执行以下命令

:set nocompatible

:set nocompatible

回答by AMing

This works for me:

这对我有用:

map ^[[A <up>
map ^[[B <down>
map ^[[C <right>
map ^[[D <left>

To type the sequence for each arrow key, you need to press ctrl-v, then the arrow key.

要键入每个箭头键的序列,您需要按ctrl- v,然后按箭头键。

For example, to type the first line:
m, a, p, space, ctrl-v, , space, <, u, p, >

例如,输入第一行:
m, a, p, space, ctrl- v, , space, <, u, p,>

This also might work:

这也可能有效:

set t_ku=^[[A
set t_kd=^[[B
set t_kr=^[[C
set t_kl=^[[D

More information is available here.

更多信息请点击这里。

回答by Deivide Oliveira

I'm on a MacBook Pro with OSx El Captain (version 10.11.1) and was having the same problem after updating my Vim with Homebrew.

我在一台装有 OSx El Captain(版本 10.11.1)的 MacBook Pro 上,在用 Homebrew 更新我的 Vim 后遇到了同样的问题。

My Vim version is 7.4.1063.

我的 Vim 版本是 7.4.1063。

I was having the problem with the Terminal app as well as the iTerm app (build 2.1.4).

我遇到了终端应用程序和 iTerm 应用程序(版本 2.1.4)的问题。

To solve this problem, I followed some of the instructions in the previous answers from @devsathish and @Kailash. The steps I followed were:

为了解决这个问题,我遵循了@devsathish 和@Kailash 之前答案中的一些说明。我遵循的步骤是:

1 - Create a .vimrc file with touch ~/.vimrc
2 - Add the following to it:

1 - 创建一个 .vimrc 文件touch ~/.vimrc
2 - 添加以下内容:

set nocompatible
set backspace=indent,eol,start

Now the arrow keys and the delete/backspace keys work as expected. I didn't have to change my $TERMenv variable as suggested in some of the previous answers.

现在箭头键和删除/退格键按预期工作。我不必$TERM像之前的一些答案中所建议的那样更改我的env 变量。

I hope this helps others with the same problem.

我希望这可以帮助其他有同样问题的人。

回答by Nianliang

I'm using iTerm2 with spf13-vim, and have same problem today.

我正在将 iTerm2 与spf13-vim 一起使用,今天遇到了同样的问题。

It caused by removing plugin vim-autoclose. This solution fixed it.

它是由删除插件 vim-autoclose 引起的。该解决方案修复了它。

Just add following lines into your .vimrc

只需将以下几行添加到您的 .vimrc 中

if &term[:4] == "xterm" || &term[:5] == 'screen' || &term[:3] == 'rxvt'
  inoremap <silent> <C-[>OC <RIGHT>
endif

回答by Mrki

This is usually caused by the wrong $TERM environment variable. Not sure which ones are supported on your system but you can try with "linux" or "vt320":

这通常是由错误的 $TERM 环境变量引起的。不确定您的系统支持哪些,但您可以尝试使用“linux”或“vt320”:

export TERM=linux

导出 TERM=linux

回答by MindTooth

To make sure that my Terminal is working great with Vim 7.3 in Show Leopard, I have done the following:

为了确保我的终端在 Show Leopard 中与 Vim 7.3 配合良好,我做了以下工作:

  1. Installed the latest Vim via Homebrew.
  2. Set path to enable the latest Vim. E.g.: export PATH=/usr/local/bin:$PATH
  3. Added export TERM=linuxto my .bashrcfile.
  4. Created a .vimrcfile with some options (formerly linked here, link went dead.)
  1. 通过Homebrew安装了最新的 Vim 。
  2. 设置路径以启用最新的 Vim。例如:export PATH=/usr/local/bin:$PATH
  3. 添加export TERM=linux到我的.bashrc文件中。
  4. 创建了一个.vimrc带有一些选项的文件(以前链接在这里,链接失效了。)

When so is done, everything should work. However, I have experienced that some text don't seem to remove, like its protected until I either ddor x. Has anyone experienced something similar? Also, please share comments on my small guide above.

完成后,一切都应该有效。但是,我经历过某些文本似乎不会被删除,例如在我ddx. 有没有人经历过类似的事情?另外,请分享对我上面的小指南的评论。

回答by Koshmaar

None of the above worked for me. Running vim in blank state with vim -u NONE -U NONE -Nmade it work ok, and because I had not installed any plugins, I knew problem is in my vimrc. So I started commenting out sections from it, and at one moment problem disappeared.

以上都不适合我。在空白状态下运行 vimvim -u NONE -U NONE -N使其工作正常,并且因为我没有安装任何插件,我知道问题出在我的 vimrc 中。所以我开始注释掉它的部分,然后问题就消失了。

The culprit was this line: inoremap

罪魁祸首是这一行: inoremap

Even though it was recommended in a very well written course (http://learnvimscriptthehardway.stevelosh.com/chapters/10.html), it broke the arrow keys on Mac OS X 10.10. Basically, you shouldn't overwrite esc, as the other SO answer explains: How to disable Esc and cursor keys in vim

尽管它在一个写得很好的课程 ( http://learnvimscriptthehardway.stevelosh.com/chapters/10.html) 中被推荐,但它在 Mac OS X 10.10 上破坏了箭头键。基本上,你不应该覆盖 esc,正如另一个 SO 答案所解释的:如何在 vim 中禁用 Esc 和光标键

回答by granin

This is what worked for me (based on initial solution from @Phoenix above)

这对我有用(基于上面@Phoenix 的初始解决方案)

imap ^[OA <ESC>kli
imap ^[OB <ESC>jli
imap ^[OC <ESC>lli
imap ^[OD <ESC>hli

for each ^[
type the sequence press ctrl-v, then ESC

对于每个 ^[
键入序列按 ctrl-v,然后按 ESC

回答by Vasu

I have used following code in my .vimrc file, and it has resolved my problem with arrow keys.

我在我的 .vimrc 文件中使用了以下代码,它解决了我的箭头键问题。

...
...
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start
...
...

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif
...
...   

I have posted my complete .vimrcfile Here. Hope it helps !

我已经在这里发布了我的完整.vimrc文件。希望能帮助到你 !