6

What I struggle with:

I'm configuring ~/.inputrc file to be same as mine custom emacs key-bindings and I'm struggling very much with readline's key sequences.

What I mean by that is that if I want to set <up> / <down>, I have to set it to "\e[A" / "\e[B"

How can I infer keyseq for <F1>..<F12> or even if I want to bind something to let's say (kbd "C-x <M-f7>") in emacs terminology (ie: to [control]+[x] [alt]+[f7] be one keyseq)?


What I want:

Is there any command that tells me for certain key on keyboard what its escape sequence? If there isn't any command, is there any other resource (article/table/...) with some hints?

--> goal: replace <KEY SEQUENCE> with proper keyseq

"<f3>" : start-kbd-macro "<S-f4>" : end-kbd-macro "C-x <C-M-S-f4>" : dump-macro "<f4>" : call-last-kbd-macro ... more keybindings ...


2 Answers2

4

I found solution: use emacs -nw and function insert-quoted (default bind to Ctrl+q).

Ctrl+q will result in ^[[A
Ctrl+q F1 in ^[[[A

Lines in ~/.inputrc will then be following (results may vary depending on environment - mostly $TERM variable):

"\e[[A": "pressed up key"
"\e[[[A": "pressed F1"

Motivation to change your .inputrc can be following.

Don't you like emacs-like keys for navigating along line and history?
I don't and I prefer ErgoEmacs key bindings because they are logical and I want to use them not only in Emacs but system wide.

"\ej": backward-char
"\el": forward-char
"\ei": previous-history
"\ek": next-history
"\eh": beginning-of-line
"\eH": end-of-line
"\eu": backward-word
"\eo": forward-word
"\eg": kill-line
"\eG": backward-kill-line
"\ee": backward-kill-word
"\er": kill-word
"\ed": backward-delete-char
"\ef": delete-char
"\ez": undo
"\ex": kill-region
"\ec": copy-region-as-kill
"\ev": yank
"\e;": forward-search-history
"\e:": reverse-search-history

I have written "sudo aptitude install" so many times (usually after fresh install) that I have M-a M-i (ie Alt+a Alt+i) as shortcut for that (because alias to same thing don't autocomplete)

"\ea\ei": "sudo aptitude install "

There are plenty other reasons why you should have your own ~/.inputrc ...

cocomac
  • 3,824
1

Vim readline filetype & syntax

I found that Vim has a readline filetype plugin, which can help to rewrite your .inputrc.

The plugin should auto-detect .inputrc, and if not you can call :set filetype=readline to select it.

Assuming you have an empty line such as "": readline-command you can place your cursor inside the "" quotes in insert-mode (i) and then press Ctrl+V then keystroke-combination to insert many of the more magical incantations.

Assuming syntax completion is on you can auto-complete readline commands.

HKOB
  • 111
  • 2