3. BackSpace
There are several places where you don't notice that BackSpace is faulty. You may even believe that your system is OK, see tried it - it works! Attempting to fix it causes other problems to occur elsewhere. The knock on effect cascades through several steps. Fixing it is the reverse of how the problem started in the first place. The problem and the answer, is that the key above the Return key is the BackSpace key, and nothing else. It always has been, and it always should be. Everywhere (except Dec terminals). Everyone will tall you to use the xmodmap fix. This is a quick fix that solves the most obvious symptom, but the "real" fix, is to edit the keyboard table in /usr/lib/kbd. When you are finished, you should NOT have the xmodmap incantation anywhere (except in memory, for use on other peoples systems). |
On DEC VT100 terminals (the old original ones), there is no BackSpace key, there isn't even a key above the Return key. To get a CTRL-H you had to type CTRL-H. So the community of DEC users used the Delete Key instead (to delete to the left).
DEC users naturally setup up their stty erase and xmodmap configurations so that DEL deleted to the left and were happy.
Most other manufacturers, followed ASCII and provided a BackSpace key, returning CTRL-H. They set their stty erase and xmodmap files, and were happy.
Then DEC added a physical key in that location, and to keep users happy (damned installed base), made that key return the DEL character 127. DEC users changed nothing, got a new key and were still happy.
Years later, the East-Coast/West-Coast divide grew, and then smudged. At some time confusion arose, and every combination of available fixes was applied, to make different keys do different things.
The legacy, is that the UK Linux keyboard map (and several others also) has the BackSpace key defined as Del, returning 127 not 8! The system, as distributed, has been customised into the DEC set of fixes, instead of the proper ones. Except in trix of course, and soon your machine. (At least until the next upgrade!).
bash has it's own line editing functions, that responds to CTRL-H whether it is set in stty or not.
Bash also responds to Del (CTRL-?) in the same way. It always works, and never deletes to the right.
To test it, (before and after) run vi, insert CTRL-V BackSpace.
Every PC key has a unique PC-Kbd ScanCode. BackSpace key is ScanCode key 14. Different PC keyboards in different countries can have identical keyboards, but with different engravings on the key-tops. Different countries can also have different shapes of keyboards, but the computer doesn't really know this. The keyboard tells the computer that switch(14) was pressed or released, and the computer interprets that into an actual key.
The uk.map file tells the console driver what character (or function) to return for each scan code. Each key has several values and flags for Shift/Control/L-Alt/R-Alt.
Without disturbing the other settings, change the first Delete to BackSpace so that it look like:
keycode 14 = BackSpace Delete control keycode 14 = Control_underscore alt keycode 14 = Meta_Delete
That sets the key to return BackSpace, which it should, but keeps SHIFT-BackSpace as Delete, which is useful.
After editing, load the table using loadkeys uk.map. This command is also in /etc/rc.d/rc.local (or other), so that it happens every time you boot, but you can run it anytime.
To test it, (before and after) run vi, insert CTRL-V BackSpace.
This is a tricky one. The fix "keycode 22 = BackSpace" has a corresponding "un-fix" somewhere. IE some kind DEC user actually _wants_ it to Del. Look in all the file listed here, then read and follow startx, using the xmodmap -pk to see if it's been un-changed since xinit was started.
The kernel can do simple line editing, when asked to.
Applications have either line-based input, or character based input. The tty driver has it's own line-based-editing-mode, where the kernel releases the entire line, after you press Return. Before then, you can cancel the line, or other editing actions such as press BackSpace. The application (eg ftp) never sees this editing, it gets the result and doesn't have to do any complicated interaction.
The various keys (single characters) that kill-word, kill-line, kill-char, can be set or changed using the stty command. stty erase X sets the key that will be used as the BackSpace key. X can be any single character key, such as CTRL-H or even "X" (makes typing "TeX" appear as "T").
When typing stty erase ^H, you don't type the "picture" ^ then H, you type the actual key. If it is already set, either prefix it with CTRL-V, or put it into a file.
This command makes it works properly, but only after the command is run. If you put it into /etc/profile, it will be run on every users login. It won't be run before login.
If you put the command into /etc/profile, it won't be run until after you have entered the username and password. During this time the getty login progam is running on the defaults builtin to /sbin/agetty, or any configuration that your getty chooses.
To see what they are, logout of tty2 and on tty1 run:
stty < /dev/tty2
The defaults are not printed when they are the defaults. The default is Del (historical mistake). You can see that this is effective, before you login (eg over a modem) by seeing that BackSpace gets echoed as a non-destructive left move, whereas CTRL-? (Del) gets echoes as a Left-Space-Left, ie the last character of the username is removed from view.
Press CTRL-? more times than you have pressed keys, and you will login first time.
If you are running a different getty, it may have a configuration file, (/etc/gettydefs, or /etc/conf.uugetty, or ...) where you can set what you want. Try it with both BackSpace and Del to see that you can/can't login after making a typo.
I don't know where xterm gets it's stty settings from, but xterm -ls runs through /etc/profile anyway.
Vi looks at the stty settings, and allows DEL as BackSpace. It adapts intelligently to your stty settings (elvis does anyhow).
It also gives a way of seeing what any key really generates. Goto Insert-Mode (by pressing i) and type CTRL-V then the key you want, eg BackSpace, you either see ^H or ^?. Press ESC (leave insert mode) then :q! (quit without saving).
Actually CTRL-V only "quotes" the following byte. This works with function keys that start with ESC or CTRL-C, but not any second byte that would have a strange effect.
The CTRL-V key works with vi, and also with the kernel command line editor, and also with bash, and also with mc. Sort of a group standard.
X11 uses different numbers for ScanCodes (it's for virtual hardware, not just for Intel-IMB-PC keyboards), and 'that key at the top right with a big left arrow' is key-22.
Lists all of the keyboard table entries currently in use. Thats how you know that you DON'T need to do the following:
This runs xmodmap on a running X11 kernel, and remaps the key. If that helps, you can run the command every time X11 starts up. But it is better to fix the bug, and not the symptom. However, you might not have root access to run loadkeys, or have forgotten to do it on a new instalation, or simply want to run it from curiosity.
It is customary for startx or openwin, to tell xmodmap to read this file, (ie X11 scripts come pre-configured with standard places for you to put things).
If you want to (or someone else did), you can put the configuration entry in the .Xmodmap file. Only the expression within the quotes, (the xmodmap command with the -e option means run a single expression without reading from a file). Whilst there uncomment all the other entries with a !
This sets it globally for X11. It was the only entry in the file, and shouldn't really be there at all as it is a fix that shouldn't need fixing. IE this is another place to remove the patching fix from!.
If there isn't an overriding xmodmap command, then the system defaults are used. These days, the values are not listed anywhere, but loaded by XFree86 from the running Linux console. If you have defined it there (and not overriden it elsewhere), BackSpace will be properly defined, and no fix or un-fix is required.
Now that BackSpace works for X11 apps, test it again for text apps, especially those running in xterm (or rxvt, or ...). Maybe these apps should get it from the stty settings of the controlling terminal (other than themselves!)
xterm -e ftp localhost &
Actually that still fails for me, but now I know that SHIFT-BackSpace generates a Del, and the kernel command line editor undraws th ^H picture properly. IE press shift, and be happy (ish).
Don't edit /etc/XF86Config, but put a command into your $HOME .xinitrc, eg
xmodmap -e "pointer = 3 2 1" # man xmodmapor put the data part of this command in any of the config files listed above, Now you know that xmodmap does other things.