11

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 '15 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 '15 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 '15 at 11:47
14

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

3
  • // , 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 '16 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 '16 at 21:40
  • Any lore on why delete key is not delete-char by default in zsh?
    – SLCH000
    Sep 23 at 17:15

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.