一个困扰了我很久得问题:xterm中<backspace>或<delete>键无法删除敲错的字符,只能使用Ctrl+H或者VI删除模式,很不方便。操作系统是Red Hat Enterprise Linux 5.5。
Google之后发现这个问题比较普遍,但是很多建议都不能解决问题。最终在http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1298028466012+28353475&threadId=1158640发现了一个可行的办法:
stty erase <backspace>
当然在设置之前要先用stty -a查看erase=XX是不是已经设置成了<backspace>,即^?。
如果不想每次打开一个新的xterm之后都要手动输入stty erase <backspace>,可以在.env中加入
stty erase ^?
PS:发现了一个详细解释并彻底解决各种Unix/Linux窗口中<backspace>或<delete>不一致的文章:http://www.ibb.net/~anne/keyboard.html。转载如下。
http://www.ibb.net/~anne/keyboard.html
version 0.6
Last updated 11/18/2008 13:08:02
Index |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Configuration of environments...
|
||||||||||
... and applications
|
||||||||||
Athena-apps | Emacs | Joe | KDE | Less | Nedit | Netscape | Pico and Pine | Vim | Mutt | Telnet |
The keymapping problem can be traced back to the time when computers used punched tapes. The only way to correct a wrongly punched character was to punch additional bits in the tape (or rather, punch additional bits _out_ of the tape). Characters with all the bits punched were treated as deleted characters. See 'man ascii' for a list of the ASCII characterset, you'll see that DEL, (octal 177, decimal 127 and hexadecimal 7F) is the one with all the bits punched in (the ASCII code with the highest value). To be able to overwrite a character it is necessary to undo the feed between the characters first. For this the ASCII BS (octal 010, decimal 8, hexadecimal 08) was used. So to erase the last-typed character, you would have to press first BS to move back one character, and then DEL to delete the character. In newer computers either BS or DEL was chosen to move back and delete in one press.
The question to use BS or DEL was (and is...) just a matter of choice, just as different operating systems chose different ways to represent newlines, which was done by first issuing a carriage return (CR) and then a line-feed (LF). UNIX chose ASCII LF (hexadecimal 0A) to do both at the same time, Macintosh chose CR and MS-DOS both. Unfortunately, in the BS-DEL case, Linux ended up with two possibilities.
The essential point in this issue is to go for one way consistently. This page describes a way to consistently use DEL to erase the previous character, the page called The Alternative Way describes a way to consistently use BS. On the latter page there are some tips which may be useful regardless of what approach you take.
Since starting this page in 1997, most distributions have sorted out the issue. Still, some of the fixes/workarounds can be useful when working in a mixed environment, or when working on older systems. And evidently, given the number of hits the page still gets, it's a situation common to more then a few people ;-)
If you miss an application on this page, it's either because the keys are ok in the application ("If it ain't broken, don't fix it"), or because I don't know about it. In either case, don't hesitate to mail me about it.
Throughout this document, [<---] and [Delete] are used to denote the physical keys on the keyboard, the things you actually press to erase characters. There are a few things to keep in mind: ASCII values can be represented in several equivalent ways. This means that ASCII BS is equivalent to 010 in octal, 8 in decimal and 08 in hexadecimal notation. To show that a number is in hexadecimal notation '0x' is put in front of it. Finally it should be noted that BS and DEL are known to applications by their corresponding control sequences. To sum it up:Note: |
---|
ASCII BS == 0x08 == ^H |
ASCII DEL == 0x7f == 0177 == ^? | <