I stumbled across this old post because of a similar problem I had running "mg" and "Emacs" in terminals /dev/ttyvXX (not in X), where the Backspace was not doing its job.
I add stuff here for reference to people how may find a similar issue in future.
0] run
tty
to understand the kind of terminal you are using.
If you are our of X most probably you are dealing with "virtual terminals" so
in output you will see a file with a name like /dev/ttyvXX. The description below applies only in this case.
1] Analyze the keycode you are receiving from the keyboard with
kbdscan
. This is as helpful as
xev
in X !
2] Forget
kbdcontrol
, that is for the system console only, not virtual termianals.
3] If necessay, tell explicitely in /etc/rc.conf the keymap you are using, .e.g
that refers to the file /usr/share/vt/keymaps/us.kbd.
4] Modify e.g. /usr/share/vt/keymaps/us.kbd to what you want and check if it is working with
kbdmap
; toggle the selected keyaboard in and out of your modified map to force the keymap changes to be loaded.
5] You may use this trivial script to see what ascii codes are arriving to your
shell
Code:
ruby24 -e 'require "io/console"; c = STDIN.getch; puts "ascii #{c.ord} --- char #{c}" '
6] Once you know:
--] the keyboad signal code arriving
--] the keymap used for translation: keyboardCode --> asciiCode
--] the ascii code arriving to your shell after translation
=> You are ready to take actions.
In my case I needed to configure "mg" because Backspace and the "mg"
sequence "C-h" were bound to the same ascii code and "C-h" (mg help function was taking precedence).