Home key not working in terminal

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

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

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.