Thursday, March 31, 2011

Why is psql inserting a tilde when I press any of the keys in the Home key cluster?

I'm using psql 8.2.3 on FreeBSD. Every time I press Insert, Home, Delete, End, Page Up or Page Down, a tilde (~) character is inserted instead of performing the expected function of the key. Why does this happen and how can I fix it?

From stackoverflow
  • That shouldn't be a psql problem - it's os specific. A quick search on google could help.

    cowgod : Thank you. I didn't even realize it but now I see that the same behavior occurs on the command line also.
  • As mentioned in Endlessdeath's answer, this turned out to be a key mapping problem with the operating system (FreeBSD), not psql. You can make these keys work as expected by creating or adding to a configuration file for inputrc.

    You can create a file named .inputrc in your home directory with the following:

    set meta-flag on
    set input-meta on
    set convert-meta off
    set output-meta on
    
    "\e[1~": beginning-of-line
    "\e[4~": end-of-line
    "\e[5~": beginning-of-history
    "\e[6~": end-of-history
    "\e[3~": delete-char
    "\e[2~": quoted-insert
    "\e[5C": forward-word
    "\e[5D": backward-word
    

    Alternatively, you can create a global file for all users. A common practice for this is to create or add to the file at /usr/local/etc/inputrc the same lines as above and then export the variable in /etc/profile:

    export INPUTRC=/usr/local/etc/inputrc
    

    Ensure that /etc/profile is sourced by your shell (most do by default) and you're good to go. Note that the file won't be sourced until you log out and in again.

    Here are some other resources for this problem:

0 comments:

Post a Comment