0,115 ,ˆl–Ðz¾”d*j"Tâ�nãn\”Å£Ä „ ¢t?_‡I|¥ŠèªÃÂ?÷ The Linux keyboard and console HOWTO: Delete and Backspace Next Previous Contents

5. Delete and Backspace

Getting Delete and Backspace to work just right is nontrivial, especially in a mixed environment, where you talk to console, to X, to bash, to emacs, login remotely, etc. You may have to edit several configuration files to tell all of the programs involved precisely what you want. On the one hand, there is the matter of which keys generate which codes (and how these codes are remapped by e.g. kermit or emacs), and on the other hand the question of what functions are bound to what codes.

People often complain `my backspace key does not work', as if this key had a built-in function `delete previous character'. Unfortunately, all this key, or any key, does is producing a code, and one only can hope that the kernel tty driver and all application programs can be configured such that the backspace key indeed does function as a `delete previous character' key.

Most Unix programs get their tty input via the kernel tty driver in `cooked' mode, and a simple stty command determines the erase character. However, programs like bash and emacs and X do their own input handling, and have to be convinced one-by-one to do the right thing.

5.1 How to tell Unix what character you want to use to delete the last typed character

        % stty erase ^?
If the character is erased, but in a funny way, then something is wrong with your tty settings. If echoprt is set, then erased characters are enclosed between \ and /. If echoe is not set, then the erase char is echoed (which is reasonable when it is a printing character, like #). Most people will want stty echoe -echoprt. Saying stty sane will do this and more. Saying stty -a shows your current settings. How come this is not right by default? It is, if you use the right getty.

Note that many programs (like bash, emacs etc.) have their own keybindings (defined in ~/.inputrc, ~/.emacs etc.) and are unaffected by the setting of the erase character.

The standard Unix tty driver does not recognize a cursor, or keys (like the arrow keys) to move the current position, and hence does not have a command `delete current character' either. But for example you can get bash on the console to recognize the Delete key by putting

        set editing-mode emacs
        "\e[3~":delete-char
into ~/.inputrc.

`Getty used to do the right thing with DEL and BS but is broken now?'

Earlier, the console driver would do BS Space BS (\010\040\010) when it got a DEL (\177). Nowadays, DEL's are ignored (as they should be, since the driver emulates a vt100). Get a better getty, i.e., one that does not output DEL.

`Login behaves differently at the first and second login attempts?'

At the first attempt, you are talking to getty. At the second attempt, you are talking to login, a different program.