Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). The Del key works fine in OSX but in Terminal and iTerm, it inserts "~" instead of deleting forwards one character. 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). Is there any way I can simulate deleting forwards one character in iTerm?

like image 724
luxon Avatar asked Oct 21 '15 22:10

luxon


People also ask

How do I delete forward characters?

The Delete and the Backspace keys are used for the simplest delete operations. They work fully naturally: The character under the cursor can be deleted by pressing the Delete key. This is a so called forward delete.

How do I delete a word in Mac terminal?

Mac OS X Terminal: Map option+delete to "backward delete word" New! Save questions or answers and organize your favorite content. Learn more.

How do I use iTerm2 on Mac?

How do I open iTerm2 on Mac? To open iTerm 2, you simply need to double-click its icon – the one that you downloaded. If you go through the process of setting up hotkeys for the app, you will also be able to open iTerm2 through a specified by you keyboard combination.


1 Answers

If you are using zsh, try adding these lines to your ~/.zshrc file, then close and reopen the terminal:

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.


Why this? Because it seems that zsh doesn't read /etc/inputrc with the key bindings by default.

like image 57
ricpacca Avatar answered Sep 21 '22 19:09

ricpacca