Delete Key Doesn't Work in xterm - How to Fix It?

Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
I am running Apple's X11. From within an xterm, when I press the Delete key, I get a nasty key code that xterm doesn't recognize as delete. I would like to remap that so that it works as intended. As an example, this would remap the Backspace key:

xmodmap -e "keycode 59 = BackSpace"

What is the magic keycode and word for Delete? Something along the lines of:

xmodmap -e "keycode xy = Delete" ?

In this case, what is the value of "xy", and is "Delete" the correct keyword?

Thanks!
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
If the delete key functions the same way as the backspace key. Then this is what I do at the command line.

stty erase deletekey
 
OP
mac57
Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
Nope, that didn't do it! I opened an xterm and tried this, but I still get junk when I press the delete key.
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
You did press the delete key, in place of the word deletekey and not type deletekey. I should have made it more clear.
 
OP
mac57
Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
Well not exactly rman. In the "right out of the box" configuration (Apple's X11 as it came, I haven't mod'd Xresources, Xmodmap, etc.), when I press the Delete key I get some form of escape sequence that puts a few characters of jibberish in the screen. Starting from there, if I type "stty erase <press Delete key>" and try using the Delete key (desired behaviour is that it deletes the key under the cursor, not the one to the left of the cursor, like Backspace does) I still get jibberish.

I did eventually modify this such that the Delete key at least behaved like Backspace (trying out a suggestion I found on Google) by adding

xterm*.deleteIsDEL: true

to a .Xresources file. If I now restart Apple X11, the Delete key works like the Backspace key.

If I now follow your prescription above, pressing the Delete key where you say "deletekey" simply backspaces! I tried doing it "literally" (ctl-v, then Delete), the Delete kill still behaves like Backspace.

I have also tried "stty kill <press Delete key>" to no good end.

This is pretty frustrating. I have a perfectly good Delete key that will only Backspace. I am sure that some magic combination of Xresources, xmodmaps and sttys will do the job, but I am stuck for the prescription!
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
interesting, I would have to look farer. I have never used the delete key. Except for control-alt-del of course. :)
 
OP
mac57
Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
Solved it! Finally, here is how to make your Delete key act like a real Delete key, which is to say that it deletes the character currently under the cursor rather than doing a Rubout (delete the character to the left of the cursor) or worse still, insert a "~" into the line.

This solution is specific to the bash shell, and works for bash under both Apple's X11 xterm and Terminal.app (bash is the default shell in both cases).

Create a file in your home directory called .inputrc - Put the following single line into that file:

"\e[3~": delete-char

Restart Terminal.app or create a new xterm if using X11. Thats it! I have tested it and it works like champ. bash apparently reads this file every time it starts.

You can read LOTS more about this problem and related problems by Googling the phrase "bash delete key". Apparently this is a VERY common issue.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top