start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 5.8 Terminal Escape Sequences Chapter 5
Setting Up Your Terminal
Next: 5.10 Finding What Terminal Names You Can Use
 

5.9 Setting Your Erase, Kill, and Interrupt Characters

Have you ever sat down at a terminal where the "erase" key (the character that deletes the last thing you typed) wasn't where you thought it would be? If you have, you know how disorienting this can be! The stty (41.3) command gives you a way of changing the erase character (along with several others) so you can restore some order to your world.

stty takes two kinds of input. If you want to give the command interactively, type stty erase char, where char is the key you normally use for erase - BACKSPACE, DELETE, whatever - followed by RETURN. This will do the trick, provided that the character you type isn't already used for something. If the character is in use, or if you're putting stty commands into your .login or .profile file, it's better to "spell these characters out." "Control" characters in .login are allowed, but they aren't a great idea. If you like to use the BACKSPACE key as the erase key, add the line below:

stty erase ^h

If you want to use the DELETE key, quote the ? character so the shell won't treat it as a wildcard (1.16):

stty erase ^\?

That is: stty lets you represent a control key with the two-character combination ^x, where ^ is the literal key ^ (caret) and x is any single character. You may need to put a \ before the x to prevent the shell from interpreting it as a wildcard [and a \ before the ^ to prevent some Bourne shells from interpreting it as a pipe!-JP ].

Of course, you're not limited to the BACKSPACE or DELETE keys; you can choose any other key you want. If you want to use "Z" as your DELETE key, type stty erase\ Z. Just make sure you never want to type a real Z!

Table 5.1 lists functions that stty can change.

Table 5.1: Keys to Set with stty
CharacterFunctionGood SettingSee Article
eraseErases the previous character.^\? (DELETE)5.9
killErases the entire line.^u (CTRL-u)9.2
weraseErases the previous word.^w (CTRL-w)9.2
intrTerminates the current job.^c (CTRL-c)38.9
quitTerminates the current job, makes a core file.^\\ (CTRL-\)38.9
suspStops the current job (so you can put it in the background).^z (CTRL-z)12.1
rprntRedisplays the current line.^r (CTRL-r)9.3

The command stty everything (for BSD UNIX) or stty -a (for System V) shows all your current terminal settings. The werase and rprnt characters aren't implemented on many System V versions.

As a historical note: the erase character was originally #, and the kill character was originally @. These assignments go back to the olden days (41.2), when terminals printed with real ink on real paper and made lots of noise. However, I'm told that there are some modern systems on which these settings are still the default.

NOTE: Terminal emulators, editors, and other programs can fool around with all of this stuff. They should be well-behaved and reset your terminal when you leave them, but that's often not true. So: don't expect your settings to work within a terminal emulator; they may, or they may not. And don't expect your settings to be correct after you exit from your terminal emulator. Again, they may, or they may not. The tset program also fools around (5.11) with key settings. Therefore, in your shell setup files (2.2), put stty after tset.

- ML


Previous: 5.8 Terminal Escape Sequences UNIX Power ToolsNext: 5.10 Finding What Terminal Names You Can Use
5.8 Terminal Escape Sequences Book Index5.10 Finding What Terminal Names You Can Use

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System