21

In zsh, whenever I press Fn+Delete (which is forward delete) a tilde (~) gets inserted. This indicates zsh doesn't have the key bound.

How do I bind it, and make it behave normally (delete in front of the cursor)?

19

First figure out what sequence it generates.

echo "CtrlVFnDelete" | od -c

Then bind that sequence using the normal zsh bind mechanism.

  • 1
    ~ > echo "~"|od -c 0000000 ~ \n 0000002 ~ > What do I do with this information now? – Thomas R Jul 30 '10 at 16:08
  • 10
    @rixth: It's not actually outputting only a tilde. You can't use echo "~" , you have to actually follow the directions that Ignacio gave you. On my system, it's ^[[3~ (or as od outputs: 033 [ 3 ~). So the command would be bindkey "^[[3~" delete-char which would go in your ~/.zshrc. – Dennis Williamson Aug 2 '10 at 1:05
  • 2
    To clarify the above, ctrl-v is a special escape sequence that means "insert the next character I press as a literal unescaped character, instead of doing whatever it usually does." Meaning that it doesn't get converted to ~, but stays as the escape sequence. – NHDaly May 23 '16 at 23:38
  • I don't understand how to use the output of the above to derive the bindkey. My output is 0000000 C t r l V F n D e l e t e \n 0000016. – Oliver Joseph Ash Jun 22 '16 at 13:32
3

For me the above didn't do the trick so I added the following key binding to my ~/.zshrc:

bindkey "\e[3~" delete-char

FYI: I am on a Mac (High Sierra).

  • And how to know the code for any other key I want to bind, e.g. Fn+F1? so that I can set the corresponding codes in my ~/.zshrc. – alexventuraio Mar 29 '18 at 17:34
  • 1
    You could type cat and then type the keys. Fn+F1 gives me ^[OP for instance. – LordTribual Apr 3 '18 at 7:37
1

bindkey 'CtrlvFnDelete' delete-char

This will bind Fn+Delete to delete forward a single character. If the above is not clear, you need to type Ctrl+v, Fn+Delete between typing the quotes. Ctrl+v allows you type the literal escape escape sequence of whatever key comes after it.

You can put this line in your ~/.zshrc file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.