- xterm, rxvt and many other (but not all) such programs make
use of the readline library to provide tons of additional functionality
on the command line. Do a man
readline to see the very long list
of features supported by this library and which, by extension,
applications that use it have.
- The readline library uses
the configuration file: ~/.inputrc
- To enable the
Page up, Page down, Home, Insert, Delete, End, F1 - F12 keys etc, you
need to add entries to ~/.inputrc so that readline can process these keys
properly.
- A system-wide inputrc file
can be found at /etc/inputrc
- The ~/.inputrc file I use
is shown below:
|
#readline
input file
#esc is denoted by \e which is equivalent to C-[
"\e[3~": delete-char
"\e[7~": beginning-of-line
"\C-[[8~": end-of-line
"\e[1~": beginning-of-line
"\e[4~": end-of-line
|
The format is: "key_code":
readline_command
where readline_command can be
obtained from the readline man page. The man page contains a list of
all supported commands and describes each one quite well.
Getting the key_code isn't hard either. While probably not the best way
of doing things, I find the following works very well:
- Open an xterm/rxvt
- Start an X-windows program in the FOREGROUND. eg. start
"eog" or "gimp" or "xv" or "gedit" or any other X program you like. But
make sure you don't run it in the background i.e. run "xv" and not
"xv&"
- When the program starts, you don't get your shell prompt
back in the xterm/rxvt. Switch to the xterm/rxvt window and press a
key, the "delete" key for example. When you do, you'll see something
like ^[[3~ printed out. Replace the ^[ with \e and use that value as your
key_code. So ^[[3~ now
becomes \e[3~.Then, look
in the readline manpage for what action you want to take eg. delete-char is the readline command to delete the
character under the cursor, which traditionally is done by the "delete"
key.
- Add a line to
~/.inputrc using the key_code and readline_command you obtained. The
brilliant thing about this is that you can now make a key to
practically anything you want. The "delete" key can now behave like
backspace, or you can have a command run when you press "F1". All you
have to do is match the key_code and readline_command values
appropriately!!!!
- Restart xterm/rxvt for the changes to take effect. This
apparently does not work on aterm. I think it does work in Eterm
however.
|