Defindit Docs and Howto Home

This page last modified: Mar 17 2008
keywords:xterm,vt100,terminal,console,konsole,ansi,control,sequence,del,delete
description:How the keypad Delete key is broken with OSX bash.
title:Mac OSX bash del broken with ^[3~


The bug
-------

If you are at the bash command line in OSX, and try to use the keypad
delete key, what happens is that a ~ (tilde) is printed instead of the
character to the right of the cursor being deleted. This is not the
case with Linux or other *nix systems. 

I know of no fix for this problem.


Normal behavior
---------------

My setting in bash (and apparently the default) is to use Emacs keys
(what Emacs calls key bindings). Thus delete is ^D (control-d) and
this normally has the same effect at the keypad Delete key which is to
delete the character to the right of the cursor. Backspace is
different and erases the character to the left of the cursor.



Diagnosis
---------

Use the cat command to enter unmodified keys into a text file. Edit
the file with Emacs, and switch to hexl-mode in order to see the hex
character codes. I'm logged in as mst3k on system athena which is a
OSX Tiger server. Use cat to write into a file tmp.txt. After entering
the cat command as below, press the Delete key three timess. End the
input by pressing return, then control-d. This is a standard trick
that works on all *nix systems, as far as I know. (In fact, you can
end the input with ^D alone; you don't need the return.)

[mst3k@athena mst3k]$ cat > tmp.txt
^[[3~^[[3~^[[3~
[mst3k@athena mst3k]$

Now you can edit tmp.txt with Emacs, and change mode to hexl-mode to
see the control characters. (M-x hexl-mode) The hex bytes are:

1b 5b 33 7e

This might be written:

ESC [ 3 ~
ESC [3~
^[[3~

The hex 7e is decimal 126 or octal 176 also known as tilde.

I've got an ASCII chart here:

http://defindit.com/ascii.html


Looking over the Xterm and VT100 standard control sequences, this
rarely appears. It seems to be the numeric keypad Del key when Num
Lock is off. One site called it F9, which isn't quite true.

I checked several terminal applications including Linux Xterm, Linux
KDE Konsole, and Mac OSC Terminal. All have the same control sequence
for this key. 

If you know how to fix OSX bash, please drop me a note.