Home key not working in terminal

96

Solution 1

Escape sequences sent by function and cursor keys consist of an escape character followed by printable characters. Press Ctrl+V then Home. This will insert the escape sequence literally. Then add a bindkey instruction to your ~/.zshrc.

The instruction is likely to be (note O, not 0):

bindkey '\e[OH' beginning-of-line
bindkey '\e[OF' end-of-line

Solution 2

I found I had to hit CTRL-v, let go, then the Home or End key to get the sequences ^[[H and ^[[F for Home and End respectively. Adding the following lines to the .zshrc file solved the problem for me:

bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line

Solution 3

I'm on fedora now yet I suggest you to read Archlinux's wiki carefully, all of it: Home and End keys not working.

What I did to fix it:

  1. Press Ctrl-V Home, the escaped sequence for Home key is printed. It is not \e[4~ and \e[1~ as I expected to be by looking at /etc/inputrc. It was [H and [F

  2. Extract the terminal info infocmp $TERM >terminfo.src

  3. Open that file for editing, such as vim terminfo.src, look for khome and kend it's assigned to something, let's say khome=\E[1~ and kend=\E[4~ which is not working in this case. remove it and replace it with the sequence you found in step #1, so for me, after editing it was: khome=\E[H and kend=\E[F.

  4. If you want to play it safe make sure [F and [H (or whatever sequence you just used) is not assigned to something else or things will be messed up!

  5. run tic terminfo.src which creates ~/.terminfo directory.

  6. On top of .zshrc before any and all other commands, put: export TERMINFO=~/.terminfo

Open a new terminal window and you should be fine, home and end must be working now.

P.S: The bindkey method should theoretically work and is easier, but it didn't for me.

Solution 4

Add these lines to /etc/zshrc and then do a source /etc/zshrc (taken from here)

bindkey '\e[1~'   beginning-of-line  # Linux console
bindkey '\e[H'    beginning-of-line  # xterm
bindkey '\eOH'    beginning-of-line  # gnome-terminal
bindkey '\e[2~'   overwrite-mode     # Linux console, xterm, gnome-terminal
bindkey '\e[3~'   delete-char        # Linux console, xterm, gnome-terminal
bindkey '\e[4~'   end-of-line        # Linux console
bindkey '\e[F'    end-of-line        # xterm
bindkey '\eOF'    end-of-line        # gnome-terminal

Solution 5

This answer explained my problem really good and fixed it.

https://stackoverflow.com/a/686458/5472892

TL;DR: Change your PuTTY terminal type from default xterm to linux.

Maybe someone can use it too.

Share:
96

Related videos on Youtube

ASD
Author by

ASD

Updated on September 18, 2022

Comments

  • ASD
    ASD over 1 year
    SELECT
        description
    FROM 
        diagnosis_mapping 
    LEFT JOIN
        diagnosis_codes
    ON
        diagnosis_codes.codeid = diagnosis_mapping.codeid
    
    SELECT
        description
    FROM 
        diagnosis_mapping 
    LEFT JOIN 
        diagnosis_codes
    ON
        diagnosis_codes.codeid = diagnosis_mapping.secondarycodeid
    

    How to merge these 2 queries and get info in a single resultset? In first i need to match with codeid and in second i need to match with secondarycodeid to the same mastertable to fetch the description of both.

    • bahamat
      bahamat over 12 years
      Do you have a .inputrc in your home directory? Does this happen with a freshly created user? Did this always happen, or did it start one day?
    • Chris Perkins
      Chris Perkins over 12 years
      No I don't have .inputrc. I don't permission to create new user. This was always like that. I'am living with ctrl +a and ctrl+e.
    • bahamat
      bahamat over 12 years
      I guess in that case I won't suggest ctrl+a & ctrl+e ;-)
  • Wim
    Wim over 14 years
    Also best give an alias to the result fields (a.description desc_a, b.description desc_b) as most frameworks returning an associative array (f.i. PHP's mysql_fetch_assoc) ignore the table name component and would otherwise give you back only one description field.
  • Tatu Ulmanen
    Tatu Ulmanen over 14 years
    @Wim, you're absolutely right, my example wouldn't be very usable without them. I've edited my answer.
  • ASD
    ASD over 14 years
    Its Working. Thanks. Even the idea of giving alias to the resultfields is cool. Its great. Thanks for all your help in getting me done.
  • Chris Perkins
    Chris Perkins over 12 years
    nothing gets printed when I press Ctrl then Home. Nothing happens. Tried changing 0 to O as well.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' almost 7 years
    @balki It's Ctrl+V, not Ctrl. I just realized there was a formatting problem in my answer.
  • Chris Perkins
    Chris Perkins almost 7 years
    Thanks! :) I am now used to ctrl + a and ctrl +e and vi mode
  • Kasia Gauza
    Kasia Gauza about 4 years
    Also tested in CentOS + bash - works! Thank you :)
  • Tyler Kelly
    Tyler Kelly over 3 years
    +1: it was mentioned in the link, but i was unaware that if doing ctrl-v gave me ^[[H that you should replace the ^[ with \e to get \e[H
  • David Balažic
    David Balažic about 3 years
    So now it wont work in terminals that properly emulate xterm? Or does he have a broken terminfo?
  • stwr667
    stwr667 about 2 years
    I had this problem but only in IRB ruby shells, not in ZSH shells. To fix, I added "\e[H":beginning-of-line and "\e[F":end-of-line lines to ~/.inputrc