Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Make the forward delete key work in Terminal Apps
Blast that forward-delete key (just below the Help key on a standard Mac keyboard)! It just keeps inputting a '~' when pressed, instead of deleting the next character. Luckily, there is an easy solution. In clean OS X apps, including Terminal, Control-Option-D does what we want the forward-delete key to do.

So go to Terminal's Terminal menu, pick Window Settings, and then choose "Keyboard" in the pop-up menu. Double-click on the 'del (forward delete)' key, and in the sheet that pops open, activate the input box just below "Action." Type Control-Option-D, and you should see '04' in the box. Click OK, close the Terminal Inpsector window, and you should now have a working forward-delete key. Yay!
    •    
  • Currently 4.44 / 5
  You rated: 5 / 5 (9 votes cast)
 
[32,850 views]  

Make the forward delete key work in Terminal | 18 comments | Create New Account
Click here to return to the 'Make the forward delete key work in Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Make the forward delete key work in Terminal
Authored by: JHromadka on Jun 10, '05 11:52:04AM

Thank you so much! The original string is \033[3~ and the new one is \004 after entering the sequence.

---
James Hromadka



[ Reply to This | # ]
Make the forward delete key work in Terminal
Authored by: ghay on Jun 10, '05 12:11:01PM

In 10.4 I let the OS decide which kind of keyboard I was using (Logitech Elite behind a Belkin KVM) and presto - with no more modifications forward delete works in terminal and emacs.



[ Reply to This | # ]
Make the forward delete key work in Terminal
Authored by: ritawang on Jun 12, '05 11:15:32PM

I can see and edit the input box just below "Action." , but after I typed Control-Option-D, there is no '04' in the box. However, i clicked "OK", and it works!

Thx!



[ Reply to This | # ]
Make the forward delete key work in Terminal
Authored by: restiffbard on Jun 10, '05 02:40:14PM

Awesome. This is just the keen bean.

I want to hug you. :)



[ Reply to This | # ]
Make the forward delete key work in Terminal
Authored by: pauljlucas on Jun 10, '05 02:56:15PM

I'm not sure what shell in Terminal you're using, but Control-Option-D is the same as Control-D that means End-of-File.

If you're using bash with vi editing, you want the Delete key to map to 'x'.

---
- Paul



[ Reply to This | # ]
Make the forward delete key work in Terminal
Authored by: tbdavis on Jun 10, '05 04:08:01PM

Under bash, the CTRL-d key functions as DELETE (when there are characters on the line) and as END-OF-FILE (when there are no other characters). The problem is that if you delete all of the characters, you will close that shell.

Another option is to use the bash NEXT-CHARACTER and BACKSPACE combinations: CTRL-f BACKSPACE. The problem with this is that when you get to the end of the line, you will still delete the previousl character.



[ Reply to This | # ]
Make the forward delete key work in Terminal
Authored by: pauljlucas on Jun 10, '05 05:50:17PM

Not in my bash it doesn't. To get characters on the line, you have to type something. To get characters in front of the cursor, you have to exit vi insert mode by pressing escape. You then have to move back a few characters. Then when I type Control-D, it enters the command and doesn't delete anything.

---
- Paul



[ Reply to This | # ]
Make the forward delete key work in Terminal
Authored by: Anonymous on Dec 22, '06 09:29:46AM

The best solution in this vein that I've worked out is to use the key combination space, control-T, backspace, backspace. That inserts a space, transposes the space and the next character while moving the cursor forward, then two backspaces delete the two. When you're at the end of a line, this doesn't produce a bell sound/flash like control-F, control-H does.



[ Reply to This | # ]
Make the forward delete key work in Terminal
Authored by: DylanMuir on Jun 12, '05 01:20:07PM
A better way to do this is by using ~/.inputrc.

This file sets options for the readline library, used by bash and other terminal programs to handle keyboard input. If you include the line

"\e[3~": delete-char

in ~/.inputrc, then the default Terminal.app settings will work perfectly, and you'll be able to delete to your heart's content without loggin out inapporopriately.

[ Reply to This | # ]

Make the forward delete key work in Terminal
Authored by: googoo on Jun 13, '05 02:25:41PM
I think there should be a backslash before the "e" in your .inputrc command. It should read

"\e[3~": delete-char

Tcsh users try adding this line to your .login file instead

bindkey "\e[3~" delete-char

-Mark

[ Reply to This | # ]

ARG!!! That #%@ backslash
Authored by: googoo on Jun 13, '05 02:30:25PM
The same thing happened to my backslashes! For bash users, the .inputrc file should have the line

"\e[3~": delete-char

and for tcsh users, the .login (or appropriate initialization file) should have the line

bindkey "\e[3~" delete-char

-Mark

[ Reply to This | # ]

ARG!!! That #%@ backslash
Authored by: googoo on Jun 13, '05 02:32:46PM

I give up. The e-characters in both of the commands in my previous two comments in this thread should be preceded by backslash characters.

-Mark



[ Reply to This | # ]
ARG!!! That #%@ backslash
Authored by: DylanMuir on Jun 14, '05 02:49:13AM

What's the use of a code tag that doesn't preserve code?



[ Reply to This | # ]
ARG!!! That #%@ backslash
Authored by: robg on Feb 22, '06 04:38:42PM

Try the code tag in square brackets, as explained in the red text above the text area.

-rob.



[ Reply to This | # ]
Skip forwards and backwards by words in the shell
Authored by: calroth on Jun 18, '05 09:07:12PM

In my opinion, this is worthy of its own hint, or at least to be incorporated into this one. But I suppose it will languish here at the bottom of this hint, unnoticed.

Make control cursor left and control cursor right skip forwards and backwards by words in the shell.

In Terminal, go to Window Settings, then Keyboard. For "control cursor left", press Escape, then press "b". It will show as

\033b
For "control cursor right", press Escape, then press "f". It will show as
\033f
Enjoy!

[ Reply to This | # ]
Skip forwards and backwards by words in the shell
Authored by: calroth on Jun 18, '05 09:10:12PM

Needless to say, if you want to change this to the more Mac-like way of doing things, map the keys to "option cursor left" and "option cursor right". They aren't there by default, but you can create them.



[ Reply to This | # ]
Make the forward delete key work in Terminal
Authored by: ssteiner on Mar 17, '06 02:27:21AM

The config below can be added to either ~/.inputrc or /etc/inputrc to make os x terminal life just a little easier. You might also need to add the line

export INPUTRC=~/.inputrc

or

export INPUTRC=/etc/inputrc

to ~/.bash_profile

# this makes the "delete" key work rather than
# just entering a ~
"\e[3~": delete-char

# these allow you to use ctrl+left/right arrow keys
# to jump the cursor over words
"\e[5C": forward-word
"\e[5D": backward-word

# these allow you to start typing a command and
# use the up/down arrow to auto complete from
# commands in your history
"\e[B": history-search-forward
"\e[A": history-search-backward

# this lets you hit tab to auto-complete a file or
# directory name ignoring case
set completion-ignore-case On

# I'm not sure what keys these are!
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[2~": quoted-insert

From:

http://koorb.co.uk/scrapbook/



[ Reply to This | # ]
Make the forward delete key work in Terminal
Authored by: nschrems on Jun 20, '08 08:41:08AM

The problem is that the applications where the forward delete key doesn't work use the Terminfo terminal database and are probably using the curses library that depends on it ads that is the unix toolbag for writing terminal-independent programs.

In the course of trying to port a curses-depended program I wrote some years ago on a Sys V system to work in Terminal.app, I spent a bunch of hours messing around with the problem and finally solved it.

The problem is that the terminfo description of the vt100 which is the default emulation mode for Terminal.app doesn't contain a definition for the forward delete key. Furthermore, although the vt102 definition does contain a definition for dch1, I discovered that is not the correct capability to define. Apparently dch1 is the code to SEND to a terminal to have it forward-delete 1 character on the screen. Mapping the forward delete key is done with kdch1.

Now for the cookbook!
Open a Terminal.app and cd to directory with some room to play.

$ infocmp > termdef.tmp (Decompiles terminfo file for the current term type)
$ vi termdef.tmp (Going to edit the decompiled version)
-----
add the following definition
kdch1=\E3~
You can stick it in anywhere, I stuck it in a line with some other keypad definitions like:
kcuu1=\EOA, kdch1=\E[3~, kent=\EOM, kf0=\EOy, kf1=\EOP,
-----
Now recompile the term definition file
$tic terminal.tmp

That's it. You probably need admin privilege for the last step so you may have to sudo it.

If you log onto a remote server, it is the server version of the definition file that matters. If you control the server -- no problem. Just do the above stuff there. If you don't control it, you can still do an infocmp and see if kdch1 is defined. To avoid looking for it yourself, try
$infocmp | grep kdch1
If it is defined there, you can make your keyboard mapping match the definition there. If it is not defined there, you can make your own copy of it. Do everything the same as above except when you get to compiling it, use
$tic -o <dir> terminal.tmp
Probably best if <dir> is your home directory.
Set an environment variable TERMINFO to whatever you used for <dir>. This will cause programs to use your private copy of the terminal definition.



[ Reply to This | # ]