Date: Fri, 11 Nov 1994 16:41:22 -0500 From: S. Lee To: comp-os-linux-announce@uunet.uu.net Newgroups: comp.os.linux.announce, comp.os.linux.help, comp.os.linux.misc Subject: Backspace Mini-HOWTO The Linux BackSpace Mini-HOWTO by Stephen Lee $Id: Backspace-Mini-HOWTO,v 1.0 1994/11/11 21:37:05 slee Rel $ =============== 0. Introduction =============== This Mini-HOWTO document describes setting up the keyboard to handle the and keys properly. It has been annoying to me that those keys had not work consistently across different programs, so I took one afternoon and tried to fix all that. Here I document my experience so others would not need to go through the same tedious cycle I did. I'm using Slackware 2.0.0, so pathnames to files might be different from yours if you are using a different distribution. ============== 1. Terminology ============== The key on the keyboard marked "Backspace" or "<--" (not to confused with the left arrow on the cursor pad or keypad). The key on the cursor pad marked "Delete", or the key marked "Del" on the numeric keypad when NumLock is off. BS ASCII character 0x08, or control-h. DEL ASCII character 0x7F. ^D ASCII character 0x04, or control-d. [BackSpace] A X11 keysym. [Delete] Another X11 keysym. =============== 2. Basic Issues =============== I assume you came from the DOS world like I did, and is used to the mapping of function that deletes character to the left of the cursor and deletes character on top of the cursor. The most intuitive mapping is -> BS and -> DEL. This is fine unless you want to use EMACS. EMACS map control-h to its help function, which, under ASCII, is unfortunately BS. So each time you want to erase a character backwards, you invoke the help system. (Hint: to remove the question if you're not that far, press . if you have pressed other keys, you might need to press then <1> to remove the help screen.) By the way, DEL under EMACS deletes BACKWARDS, like what you'd expect for BS. One choice is to remap the keys under EMACS. Unfortunately you'll lose the " = help" mapping, and you'll have to do that to every EMACS you want to access, which is a pain. So, I decided to map -> DEL and -> ^D. This would work for both EMACS and csh, and a EMACS across a telnet or rlogin connection. Now you can use the key for editing the command line also! (Before it does the same thing as .) ============================================= 3. How to do it under text mode (non-X setup) ============================================= You need to have the "loadkeys" program from the kbd package. I believe you should have it if you're running Slackware. Another file you want is /usr/lib/kbd/keytables/*.map. Choose one that is closest to your setup (it would be /usr/src/linux/drivers/char/defkeymap.map if you have the kernel source). The keycodes are 14 , 83 , 111 . If you have slackware you should already have the following: keycode 14 = Delete Delete alt keycode 14 = Meta_Delete keycode 83 = KP_Period altgr control keycode 83 = Boot control alt keycode 83 = Boot keycode 111 = Remove altgr control keycode 111 = Boot control alt keycode 111 = Boot string Remove = "\033[3~" All you need to do is to replace the last line with string Remove = "\004" and now you have both mapping under text mode after you run loadkeys: Nekomi% loadkeys whatever.map ^^^^^^^ Shell prompt Note that this command changes the mapping for ALL Virtual Consoles. You might want to put this in your /etc/rc.d/rc.local so that it is run every time you reboot. You'll need to make sure that Linux know which key your is, so do the following on your shell prompt: Nekomi% stty erase '^?' ^^ can be "^" then "?", or type You might want to put it in your ~/.login or ~/.profile. ======================================= 4. How to do it under XFree86 (General) ======================================= I'm using XFree86 2.1, but the procedure should be the same for other versions. You need xmodmap which should be included with your XFree86. We want to map -> [BackSpace] and -> [Delete] here. So put the following in your .xinitrc: xmodmap -e "keycode 22 = BackSpace" xmodmap -e "keycode 107 = Delete" Alternatively, you might generate a map file from your whatever.map using /usr/lib/kbd/keytables/mk_modmap: mk_modmap whatever.map > whatever.xmap I think you need to remove all the "compose" command in the output, then you can use xmodmap whatever.xmap to load the keymap. Note that would be mapped to [Delete] this way (if you use the same whatever.map for text mode), so be sure to edit whatever.xmap for keycode 22 and 107. =========================== 4.1 Setting up GNU EMACS 19 =========================== GNU EMACS 19 has some X support built in. To make [Delete] work the way you expect, put this in your ~/.emacs file: (cond (window-system (define-key function-key-map [delete] "\C-d") )) while you are at it, you can map more keys like [F1] etc. I think most of the keypad is already set up so you can use etc. already. Now you can use both and , and will bring up the help. You can find out want keycode and keysym a key sends using "xev" from your shell under X. ==================== 4.2 Setting up xterm ==================== "xterm" and "color_xterm" has their own mappings different from the text mode settings. To change them, put this in your ~/.Xdefaults: .XTerm.VT100.Translations: #override BackSpace: string(0x7F)\n\ Delete: string(0x04)\n\ Home: string(0x1b) string("[1~")\n\ End: string(0x1b) string("[4~") Remember to restart your xterm and use the "stty erase '^?'" command. This maps [BackSpace] -> DEL and [Delete] -> ^D, just like in text mode so it works for non-X EMACS (try "emacs -nw") or across telnet/rlogin. It works for most xterm-derived terminals as well, like color_xterm or kterm. This also changes the mapping for [Home] and [End] so they send different codes. So I can use them in "less" :) (Hint: look up the man page for lesskey(1) for setting up cursor pad keys for "less". I think they are already set up under Slackware) ============== 5. Misc. stuff ============== - I don't know how to change the mapping under "rxvt". - when you telnet/rlogin to a remote UNIX machine, make sure it knows your setting by issuing "stty erase '^?'". - although csh/tcsh treats BS and DEL the same way, other programs don't. So your mapping might seem to work under csh/tcsh but you get wierd stuff like ^? under some programs. Solution: remember the "stty" command above.