0

Regarding mapping function keys in vi readline, I have read these two stackexchanges:


I have a MacBookPro with a touchbar. The function keys are always on, but unlike physical keys, the virtual touch bar function keys are tempermental and frequently inject junk into the commands i'm typing (this is particularly a problem when attempting to type an underscore...i get a lot of F9, F10, and maybe some F11). I don't use these keys...so i wish i could disable them. But, let's say that i could make them simply go to the end of the line.

This is one of my many attempts to map to go to the end of the line (when in insert mode):

set editing-mode vi
$if mode=vi
    set keymap vi-insert
    "<F9>": end-of-line
$endif

the result of typing "asdf" at a prompt is as follows:

TT->~$ [] (arg: 20)

I have placed "[]", above, where the cursor remains after pressing <F9>, in case that is any help.

The variations i have tried are as follows:

  • "<F9>": end-of-line
  • <F9>": end-of-line
  • 20: end-of-line
  • "20": end-of-line
  • "arg: 20": end-of-line
  • (arg: 20): end-of-line
  • "(arg: 20)": end-of-line

Update: the following .inputrc is now working to "ignore" :

set keymap vi-insert
"\e[20~":redraw-current-line
WEBjuju
  • 506
  • 1
    I don't think that "<F9>" works in readline. To see what F9 really turns into, run cat in your terminal and then press the F9 key. You should see something like ^[[20~. Once you have established the exact escape, bind it to redraw-current-line: bind '"\e[20~": redraw-current-line' (or whatever command you like). You should, of course, use just the "\e[20~": redraw-current-line in ~/.inputrc. –  Dec 20 '19 at 03:03
  • @mosvy thank you. i did try this line "^[[20~": redraw-current-line after cat showed me the ^[[20~ output. Unfortunately i'm still getting (arg: 20). Could this be related to it being the MBP touch bar? Does bind '"^[[20~": redraw-current-line go in .bash_profile? – WEBjuju Dec 20 '19 at 16:30
  • 1
    Try "\e[20~" or "\033[20~", not "^[[20~". ^[ is how escape (ASCII 27) is echoed back by the terminal when its echoctl flag is on. –  Dec 20 '19 at 17:21
  • Thanks - i did just try both of those. I have to admit something, i went back and restested everything (same results), but the reason i retested is...i wasn't sourcing inputrc after each change. So...this is important content...but i'm getting this when i source inputrc: \e[20~:redraw-current-line: command not found – WEBjuju Dec 20 '19 at 18:46
  • 1
    ~/.inputrc is not a shell script, you could not source it. To test if the binding works, either run bind '"\e[20~": redraw-current-line' in your current shell, or add just the binding the ~/.inputrc and start a new shell. If you're using the emacs keybindings, you can also re-source the ~/.inputrc file by pressing Ctrl-x Ctrl-r. –  Dec 20 '19 at 18:56
  • oh my stars, oh my stars, how wonderful to hit those F9-11 keys and nothing happen! tell, me, why not post your comments as an answer so that i can accept them? anyway, you are 100% right...(a) use \e[20~ for , (b) use redraw-current-line as the command, and (c) start a new shell to source inputrc. i have already put in 20-23 and find no reaction at all from purposeful (or accidental) input from and . Thank you. – WEBjuju Dec 20 '19 at 19:01

1 Answers1

1

This is insane but true...i was on a new server today and having forgotten completely about this question (and the answer buried in comments), I was actually googling for how to do this today. I'm posting my answer for myself or for anyone else that is having problems disabling function key input in vi commandline:

  1. create or edit your ~/.inputrc file
  2. to disable through (MacOS, Ubuntu, CentOS at least) use the following:
set keymap vi-insert
"\e[19~":redraw-current-line
"\e[20~":redraw-current-line
"\e[21~":redraw-current-line
"\e[22~":redraw-current-line
"\e[23~":redraw-current-line

As @mosvy indicates, redrawing the current line prevents the annoying "(arg: 20)" or "(arg: 21)" from ruining your command line input.

WEBjuju
  • 506