macos 如何通过 ssh 在 VIM 中修复我的删除键?(Mac OS X)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4158312/
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
How can I fix my delete key in VIM over ssh? (Mac OS X)
提问by Aeonaut
When I use VIM in the terminal on my local machine (Mac OS X Snow Leopard), the delete key is really backspace (i.e., destructive backspace).
当我在本地机器(Mac OS X Snow Leopard)的终端中使用 VIM 时,删除键实际上是退格键(即破坏性退格键)。
When I SSH into a particular server, for some reason it's regular delete (i.e., delete the character under the cursor).
当我通过 SSH 连接到特定服务器时,出于某种原因,它是常规删除(即删除光标下的字符)。
How can I change it to be consistent? I've tried a dozen solutions, but nothing seems to work.
我怎样才能改变它以保持一致?我已经尝试了十几种解决方案,但似乎没有任何效果。
Checking the "Delete sends Ctrl-H" box in Terminal Preferences->Advanced doesn't work -- this is non-destructive backspace.
在终端首选项-> 高级中选中“删除发送 Ctrl-H”框不起作用——这是非破坏性退格。
I've tried about a hundred different key mappings in VIM, to no avail.
我在 VIM 中尝试了大约一百种不同的键映射,但无济于事。
Interestingly, the key works as expected when I'm typing commands in VIM (e.g., : <something>
) -- it's only screwed up when I'm editing the actual text. Any ideas?
有趣的是,当我在 VIM 中键入命令(例如,: <something>
)时,该键按预期工作- 只有在我编辑实际文本时才会出错。有任何想法吗?
回答by Nathan Buesgens
This worked for me:
这对我有用:
:set backspace=indent,eol,start
I'm not sure exactly what it does but it is listed as a possible solution hereand here. I found this line in a vimrc file distributed with Ubuntu where the behavior of the mac "delete" key (otherwise known as the "backspace" key) works as expected without any other configuration.
我不确定它到底是做什么的,但在此处和此处将其列为可能的解决方案。我在随 Ubuntu 分发的 vimrc 文件中发现了这一行,其中 mac“删除”键(也称为“退格”键)的行为按预期工作,无需任何其他配置。
The behavior I was experiencing was a bell sound (no characters deleted) when pressing the mac "delete" key (otherwise known as the "backspace" key) in insert mode. I am using a compiled version of vim 7.3 on "amazon linux" over ssh from a mac. Pressing <ctrl-v><delete>
when in insert mode resulted in ^?.
在插入模式下按 mac 的“删除”键(也称为“退格”键)时,我遇到的行为是铃声(没有删除字符)。我正在通过 Mac 上的 ssh 在“amazon linux”上使用 vim 7.3 的编译版本。<ctrl-v><delete>
在插入模式下按下导致 ^?。
回答by Nathan Buesgens
Couple of ideas to try:
尝试的几个想法:
In your
.vimrc
file on the remote server, add this line:set term=linux
In your
.bash_profile
file (or whatever corresponds to your shell of choice) on the remote server:stty erase ^H
Note: to make this work correctly, you must type ctrl-v, then ctrl-hto type the
^H
character.Also, make sure "Delete sends Ctrl-H" is checked in your Terminal prefs.
在
.vimrc
远程服务器上的文件中,添加以下行:set term=linux
在
.bash_profile
远程服务器上的文件(或任何与您选择的 shell 相对应的文件)中:stty erase ^H
注意:要使其正常工作,您必须键入ctrl- v,然后ctrl-h键入
^H
字符。此外,请确保在您的终端首选项中选中“删除发送 Ctrl-H”。
回答by Majic Johnson
Try this: http://www.alecjacobson.com/weblog/?p=295
试试这个:http: //www.alecjacobson.com/weblog/?p= 295
I fixed the problem by changing my Terminal.app settings. Under Terminal > Preferences choose Advanced. Check “Delete sends Ctrl-H”. Now, vi and vim should understand the delete key more intuitively.
Note: Mapping the “delete” key in my vimrc file seemed like probably the correct way to do this, but that's a lot of trouble. Is there any reason not to do it this way?
我通过更改我的 Terminal.app 设置解决了这个问题。在终端 > 首选项下选择高级。选中“删除发送 Ctrl-H”。现在,vi 和 vim 应该更直观地理解删除键了。
注意:在我的 vimrc 文件中映射“delete”键似乎是这样做的正确方法,但这很麻烦。有什么理由不这样做吗?
回答by ZyX
Try adding
尝试添加
set <Del>=<C-v><Del>
to the vimrc on the target machine. Here you must type <C-v><Del>while being logged on the target machine. If this does not work, check verbose imap <Del>
: this should tell you whether some plugin has remapped <Del>
in insert mode.
到目标机器上的 vimrc。在这里,您必须<C-v><Del>在登录目标计算机时键入。如果这不起作用,请检查verbose imap <Del>
:这应该告诉您某些插件是否已<Del>
在插入模式下重新映射。