Why does `zsh` insert a `~` when I press the delete key?

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.


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! :)