Linking to pages and resources on this site is encouraged, but the links MUST be placed on a publically-accessible page. Placing links behind any form of login or access restriction is strictly forbidden.
Jed: Function keys in xterms
My preferred text editor is the
jed
editor package. I have set up custom key bindings for the function keys F1-F9 to functions I use a lot,
in a file ~/pigeon.sl which is called by an entry in ~/.jedrc :
For long it has been a source of annoyance to me that while my keybindings worked fine in
text consoles, most of them didn't work in xterms. Finally it dawned on me that this is
because some of the function keys produce wildly different codes in xterms from what they
produce in text consoles (fuck knows why), and a solution became possible.
() = evalfile("/home/pigeon/pigeon.sl");
The first step was to find out what codes the keys were actually producing, by compiling
and running the following C snippet, then pressing the function keys and noting
what codes where produced:
#include <stdio.h>
Having done that I could then modify
void main(void) {
int x;
while ((x=getchar())!=EOF) printf((x==0x0a ? "(return)\n" : "%02X "),x);
}
pigeon.sl to set up the keybindings
differently according to whether it was in a text console or an xterm:
$1 = getenv ("TERM");
Naturally, you'd replace the actions of the keybindings with your own
preferences. :-)
if ($1 == NULL) $1 = "";
if (is_list_element ("linux,console,con80x25,con80x28", $1, ','))
{
USE_ANSI_COLORS = 1; % uncomment if your console is a color one!
OUTPUT_RATE = 0;
TERM_CANNOT_SCROLL = -1; % Truth is, linux console does not scroll well.
setkey("bol", "^[[1~"); % home
setkey("toggle_overwrite", "^[[2~"); % insert
setkey("delete_char_cmd", "^[[3~"); % delete
setkey("eol", "^[[4~"); % end
setkey("page_up", "^[[5~");
setkey("page_down", "^[[6~");
setkey("self_insert_cmd","\x22");
setkey("self_insert_cmd","\x27");
setkey("exit_jed","^Q"); % Ctrl-Q
setkey("kill_line","^Y"); % Ctrl-Y
setkey("bob", "\x1b\x5b\x35\x43\x7e"); % Ctrl-Pgup
setkey("eob", "\x1b\x5b\x36\x43\x7e"); % Ctrl-Pgdn
setkey("help_prefix","\x1b\x5b\x5b\x41"); % F1
setkey("save_buffer","\x1b\x5b\x5b\x42"); % F2
setkey("exit_jed","\x1b\x5b\x5b\x43"); % F3
setkey("smart_set_mark_cmd","\x1b\x5b\x5b\x44"); % F4
setkey("pigeoncopy","\x1b\x5b\x5b\x45"); % F5
setkey("pigeonpaste","\x1b\x5b\x31\x37\x7e"); % F6
setkey("pigeonzap","\x1b\x5b\x31\x38\x7e"); % F7
setkey("insert_file","\x1b\x5b\x31\x39\x7e"); % F8
setkey("search_forward","\x1b\x5b\x32\x30\x7e"); % F9
} else { % should be executed for xterms
setkey("bol", "\x1b\x4f\x48"); % home
setkey("toggle_overwrite", "^[[2~"); % insert
setkey("delete_char_cmd", "^[[3~"); % delete
setkey("eol", "\x1b\x4f\x46"); % end
setkey("page_up", "^[[5~");
setkey("page_down", "^[[6~");
setkey("self_insert_cmd","\x22");
setkey("self_insert_cmd","\x27");
setkey("exit_jed","^Q"); % Ctrl-Q
setkey("kill_line","^Y"); % Ctrl-Y
setkey("bob", "\x1b\x5b\x35\x3b\x35\x7e"); % Ctrl-Pgup
setkey("eob", "\x1b\x5b\x36\x3b\x35\x7e"); % Ctrl-Pgdn
setkey("help_prefix","\x1b\x4f\x50"); % F1
setkey("save_buffer","\x1b\x4f\x51"); % F2
setkey("exit_jed","\x1b\x4f\x52"); % F3
setkey("smart_set_mark_cmd","\x1b\x4f\x53"); % F4
setkey("pigeoncopy","\x1b\x5b\x31\x35\x7e"); % F5
setkey("pigeonpaste","\x1b\x5b\x31\x37\x7e"); % F6
setkey("pigeonzap","\x1b\x5b\x31\x38\x7e"); % F7
setkey("insert_file","\x1b\x5b\x31\x39\x7e"); % F8
setkey("search_forward","\x1b\x5b\x32\x30\x7e"); % F9
}
The correct functioning of this lot seems to depend on the presence of
the linux.sl file, see here.
One thing I have not yet figured out is how to make Alt-key work in xterms to
activate the DOS EDIT style popup menus as it does in text consoles.
However, Esc key does activate the pop-up menus, and is an acceptable
workaround.
Back to sarge page
Back to Pigeon's Nest
Be kind to pigeons