Version française

Use of Ctrl+BackSpace in xterm

This article explains how one can use the Ctrl+BackSpace key combination in xterm and applications running in this terminal. One can probably do the same kind of things for other text terminals.

In a text terminal, whereas some key combinations yield specific escape sequences, this is not the case of Ctrl+BackSpace, which typically yields the character of code 8, exactly like the Ctrl+H combination. Thus, by default, one cannot differentiate these two key combinations. The idea it to configure xterm to generate an unused escape sequence. I have chosen "\033[7;5~" (also written "\e[7;5~", depending on the application), the code \033 or \e representing the ASCII Escape character. To do this, one adds an X resource like:

*VT100*translations: #override \n\
        Ctrl<Key>BackSpace: string("\033[7;5~")

There are various ways to do that. This will not be discussed here. Once this configuration has been taken into account, one can see it with the command cat > /dev/null, then by typing Ctrl+BackSpace:

$ cat > /dev/null
^[[7;5~

It now suffices to configure each application that will be run in xterm to recognize this escape sequence and execute the wanted function: this is a binding. For consistency with GNU Emacs and its own GUI, I have chosen to delete the word on the left (backward-kill-word).

For GNU Emacs in text mode:

(define-key global-map "\C-[[7;5~" 'backward-kill-word)

For the zsh shell:

bindkey '\e[7;5~' backward-kill-word

For the applications based on the GNU Readline library, put in the ~/.inputrc file:

"\e[7;5~": backward-kill-word


webmaster@vinc17.org