xterm中删除键无法使用

一个困扰了我很久得问题: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。转载如下。

 

 

 

 

The Linux Hall of Shame

http://www.ibb.net/~anne/keyboard.html
version 0.6 
Last updated 11/18/2008 13:08:02

 

 

These pages were originally written to address a nagging problem which bothered many people using  Linux. It has to do with the default behaviour of the BackSpace and Delete keys, which did not behave as expected. The goal of this document was and still is to make [<---] (i.e. the backspace-key on your keyboard) to erase to the left, and make [Delete](i.e. the delete-key) erase under the cursor. It seems all Linux distributions I am aware of have effectively dealt with the issue by now. However still lots of people visit these pages, presumably because the information presented here is applicable to other UNIX flavors and cross-platform environments and applications.

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 == ^?
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值