Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like the delete key (well, the Fn+Backspace combination) on my Mac to behave the same way in the Terminal as it does normally. That is, to do forward-delete. Right now it outputs tilde - at least that's what I can see.

In Binding Fn-Delete in zsh on Mac OS X I saw some hackery and tried it too:

(pressed [Fn]+[<---] inside the quotes below)

$ echo "~" | od -c
0000000   ~  \n
0000002

How can I make it behave?

share|improve this question
    
The comments on SU 169930 seem fairly clear: You should be using Control-v before pressing Fn-BackSpace, which will probably show up as 033 [ 3 ~ from od. Then use bindkey "^[[3~" delete-char to bind what Terminal sends to a function in zsh. Does that not work for you? –  Chris Johnsen May 26 '11 at 2:02
    
Tried to add bindkey "^[[3~" delete-char into my ~/.profile, restarted Terminal, and tells me it doesn't know bindkey. Added it into .zshrc, restarted Terminal, and nothing happens. I don't really think I'm using zsh. Or is it Mac's default shell? I'm an amateur in these things... :) –  Martin Janiczek May 26 '11 at 12:07
    
You can check your shell with dscl . read /Users/$USER UserShell. The default is bash. You can change your default shell with chsh -s /bin/bash. You can change just the shell used in Terminal in its preferences (Settings tool bar button, then Shell tab, change Run Command to (e.g.) /bin/zsh). –  Chris Johnsen May 26 '11 at 13:37
    
Yes, my default is bash. I tried zsh and it seems to work the way I want it to. Does the bash have a way to achieve the same result? –  Martin Janiczek May 26 '11 at 18:09
add comment

1 Answer 1

up vote 2 down vote accepted

The answer to the question to which you linked shows how to find the control sequence Terminal sends when you press FnBackspace: echo 'ControlV FnBackspace' | od -c.
The ControlV is critical to prevent special interpretation of the (likely) initial ESC character.

Terminal probably sends the four byte sequence ESC [ 3 ~.

The question to which you linked was asking about zsh. The comment on the answer gives the command to bind the sequence in zsh: bindkey "^[[3~" delete-char (usually in ~/.zhsrc).

However, bash is the default shell on Mac OS X, so the command to bind a key (and the functions available for binding) will be different if you are using bash: bind '"\e[3~": delete-char'. You will probably want to put this in a bash startup file1.

If you find that you are using bash, but you want to use zsh instead, then there are two ways to change your effective shell:

  • Use chsh -s /bin/zsh to change your default shell.
    This will change the shell that Terminal starts as well as the shell started for other login sessions (e.g. logins through SSH).
  • Configure just Terminal to use a different shell in Terminal’s preferences.
    Terminal > Preferences…, Settings tool bar button, then the Shell tab,
    change Run Command to (e.g.) /bin/zsh -l.

1 Usually ~/.bashrc, but you can also put a related line ("\e[3~": delete-char) in ~/.inputrc instead. If you put it your .bashrc, you will want to make sure that you also have a line like source ~/.bashrc in ~/.bash_profile, or ~/.bash_login (if you have neither, then create the former; if you already have exactly one of them, then use the one you have; if you have both, then you should fix that since probably only the former is being used).

share|improve this answer
    
Excellent explanation. Thank you! (oh, and it worked. :) ) –  Martin Janiczek May 26 '11 at 22:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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