21

I have set my zsh to use vim style for editing command lines.

However, when I use the Delete key, it inserts a ~ character.

Have I misconfigured my zsh?

How do I turn this off?

Do I need to go back to a different command editing mode for zsh?

I'm a bit new to zsh, and perhaps answers to this question could help other newcomers with the initial configuration.

3
  • // , OH. I have been on this forum for years, and I only now just realized that. How do I move this question to unix.stackexchange.com or stackoverflow.com? I use stackoverflow.com more. Nov 8, 2015 at 5:02
  • 7
    @AidanEdwards This "section" is not just for Windows. We are inclusive to all desktop operating systems, Linux, MacOS and Plan9 included.
    – Mokubai
    Nov 8, 2015 at 11:40
  • 2
    If you use StackOverflow with any regularity you'd know that this would get shot down quicker than you could say "Hey, why all the downvotes..." You might want to have a look at their on-topic page and compare it to ours and the same on Unix.
    – Mokubai
    Nov 8, 2015 at 11:47

1 Answer 1

30

Answering because this was the first DDG result in searching for the same issue.

First, you need to get the code for the delete key.

Go to your shell prompt, for example:

alec@su:~$

Execute the 'cat' program, which you will use to determine which code corresponds to your 'delete' key.

alec@su:~$ cat

Press 'delete' on your keyboard and cat will display the corresponding code.

alec@su:~$ cat
^[[3~

You may need to press 'enter' to display the code. I did not.

Finally, press 'Ctrl+C' to send a SIGTERM signal to cat (i.e. to quit the program execution)

alec@su:~$ cat
^[[3~^C
alec@su:~$ cat

Now, you just need to configure zsh.

For me, delete sends ^[[3~, so I can put the following into my .zshrc file:

bindkey "^[[3~" delete-char

Restart zsh and you should be good to go! :)

5
  • 1
    // , Just... wow. I can't bring myself to do anything that hack-ey, but maybe something like this shows what the problem is? May 19, 2016 at 19:32
  • 3
    By default (or perhaps after configuring vi-mode) your zsh doesn't know what to do when you press the 'delete' key. All it knows if that you pressed the key corresponding to something like ^[[3~.
    – alecdwm
    May 19, 2016 at 21:40
  • 10
    Any lore on why delete key is not delete-char by default in zsh?
    – SLCH000
    Sep 23, 2021 at 17:15
  • 3
    @SLCH000 found this archived post by Anne Baretta that explains further: The keymapping problem can be traced back to the time when computers used punched tapes. ... The linux console emulates a vt220 terminal which has the following key-mapping: ... [Delete] ---> Delete ---> "\e[3~" Oct 9, 2022 at 18:16
  • 3
    Also, if you'd like to avoid magic constants, you can use $terminfo as explained on the Arch Wiki. Oct 9, 2022 at 18:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .