简体   繁体   English

删除(转发)字符iTerm2 OSX

[英]Delete (forward) character iTerm2 OSX

I am using iTerm2 on OSX, and I am using an external keyboard with a Del (not to be confused with Backspace ). 我在OSX上使用iTerm2,我使用带Del的外部键盘(不要与Backspace混淆)。 The Del key works fine in OSX but in Terminal and iTerm, it inserts "~" instead of deleting forwards one character. Del键在OSX中运行良好,但在Terminal和iTerm中,它插入“〜”而不是删除前进一个字符。 This is easily fixable in Terminal, but in iTerm, there is no key binding or escape sequence that allows me to delete a character to the right of the cursor (the equivalent Unix command is Ctrl D ). 这很容易在终端中修复,但在iTerm中,没有键绑定或转义序列允许我删除光标右侧的字符(等效的Unix命令是Ctrl D )。 Is there any way I can simulate deleting forwards one character in iTerm? 有什么方法可以模拟在iTerm中删除一个字符吗?

If you are using zsh, try adding these lines to your ~/.zshrc file, then close and reopen the terminal: 如果您使用的是zsh,请尝试将这些行添加到〜/ .zshrc文件中,然后关闭并重新打开终端:

bindkey    "^[[3~"          delete-char
bindkey    "^[3;5~"         delete-char

These should enable your delete key on any keyboard, without manual keyboard mappings to the hex command 0x04 , which has the problem that it closes the session if the input is empty. 这些应该在任何键盘上启用你的删除键,而无需手动键盘映射到十六进制命令0x04 ,如果输入为空,则会出现关闭会话的问题。


Why this? 为什么这个? Because it seems that zsh doesn't read /etc/inputrc with the key bindings by default. 因为默认情况下zsh似乎没有使用键绑定读取/ etc / inputrc。

You can add a iTerm Keyboard Mapping in Global Preferences or a Profile-based one for the key to send a Ctrl-D (0x04) 您可以在全局首选项或基于配置文件的键盘映射中添加iTerm键盘映射,以便发送Ctrl-D键(0x04)

ie: Here I am mapping Ctrl-Delete to Erase (Ctrl-D/0x04) like an Extended Keyboard's Del key: ie:这里我将Ctrl-Delete映射到Erase (Ctrl-D / 0x04),就像扩展键盘的Del键一样:

在此输入图像描述

Like Gajus said, using Ctrl-D to delete one backspace forward also closes the terminal tab if there's no input which can be very frustrating. 就像Gajus说的那样,如果没有输入可能非常令人沮丧,使用Ctrl-D删除一个退格前进也会关闭终端选项卡。

I am using zsh, but adding the lines ricpacca suggested to .zshrc didn't work for me. 我正在使用zsh,但添加ricpacca建议的.zshrc行不适合我。

What I did instead is to map Ctrl-Delete to send the hex codes "0x06 0x08". 我所做的是映射Ctrl-Delete以发送十六进制代码“0x06 0x08”。
0x06 translates to "move one character forward", and 0x08 is just a normal backspace. 0x06转换为“向前移动一个字符”,0x08只是一个正常的退格。

Thought I'd share my solution for any other frustrated iTerm2 users that scoured the internet to no avail. 以为我会为任何其他沮丧的iTerm2用户分享我的解决方案,这些用户在网上搜索无济于事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM