I want to type a tilde in bash, but pressing F10 gives me '1~' instead of just '~'

1

1

Previously I was able to output the tilde symbol in my bash terminal by pressing F10. Now when I press F10 I get two characters: 1~. Same goes for F9/F11/F12. Weirdly, the other function keys F1-F8 give me a tilde, but I want F10 to be my tilde key.

Any ideas how to fix this?

user3055163

Posted 2018-09-19T08:20:36.207

Reputation: 49

you probably need to create a new keyboard layout for your purpose. On Windows it can be done with MSKLC. Italian keyboard: entering the tilde (~) and backtick (`) characters without changing keyboard layout

– phuclv – 2018-09-20T12:29:39.817

you can press the ~ button on the key board – rinspy – 2019-05-29T15:05:15.533

That doesn’t answer my original question, which was how you get F10 (raw) to output a tilde. – user3055163 – 2019-05-29T15:20:30.410

Answers

8

None of those keys are tilde keys. They all generate a multiple character sequence, such as ESC [24~ for the F12 key, or ESC [15~ for the F5 key (although F1–F4 are slightly different), or even ESC [5~ for the PgUp key.

The only reason you get a tilde is because Bash's key-sequence parser consumes the common part that it knows (ESC [2) and stops as soon as it knows that the full sequence will be unknown. Everything that follows (not neccessarily a tilde!) gets interpreted separately.

Note that this behavior may differ between terminal-based programs: Bash (readline) has its own code for interpreting special keys, Vim has its own, Irssi has its own again. Some programs might fully recognize your keypress as F10 (and therefore ignore it).


To make F10 an actual tilde key globally (OS-wide), search for "key remapper" tools (perhaps AutoHotkey).


To make F10 a tilde key in all terminal-based programs, search through the terminal's settings. (The 'terminal' in this case refers to ConEmu.)

The terminal might have its own functionality for redefining single keys, or perhaps creating "macros". (The ConEmu documentation suggests defining a macro with the print(…) action.)


To make F10 a tilde key in Bash (but only Bash):

  1. Make sure that your terminal emulator (ConEmu) hasn't bound F10 to some function of its own. (Plain F10 is usually not bound to anything – however, Shift+F10 is the standard key for opening the "right-click" menu.)

  2. In bash, press CtrlV (literal insert) and then F10. You will see a sequence like ^[[21~.

    (The initial ^[ represents ESC, while the rest are just literal symbols.)

    If, at this point, the key doesn't insert any sequence at all, that means it has been taken over by the terminal itself or another program – go back to step 1.

  3. Open (or create) the ~/.inputrc file in a text editor.

  4. Add this line, taking the sequence from step #2 and replacing ^[ with \e:

    "\e[21~": "~"
    

    This tells inputrc to insert a ~ upon receiving ESC [21~.

  5. Reopen the Bash shell (or press CtrlX, CtrlR to reload inputrc).

user1686

Posted 2018-09-19T08:20:36.207

Reputation: 283 655

~/.inputrc is for readline(3) library. Programs other than Bash may use it as well and some do. +1 nevertheless. – Kamil Maciorowski – 2018-09-19T10:41:30.590

1

What keyboard layout you are using?

There is a dedicated tilde ~ key just above Tab on standard US keyboard.

enter image description here

Art Gertner

Posted 2018-09-19T08:20:36.207

Reputation: 6 417

2

Many European keyboards are notorious for lacking the tilde (~) and backtick (`) keys

– phuclv – 2018-09-20T12:23:10.663

-1

I fixed this my removing ~.inputrc which had nothing useful in it anyway.

user3055163

Posted 2018-09-19T08:20:36.207

Reputation: 49

3Can you explain why removing this fixed the problem? In particular, consider the next person with this problem...what information do they need to consider to determine whether removing it will fix the problem for them? – I say Reinstate Monica – 2018-09-26T14:28:52.047