17

I am using GNOME Terminal 2.7.3 and zsh 4.3.9 (x86_64-unknown-linux-gnu)

Home and End are not working. Nothing happens and nothing gets displayed when I press them. but they work when I press shift + Home (Scrolls to the beginning of shell output.) and also work in other GUI programs. I googled and tried the following. No change :(

  885  bindkey "\e[1~" beginning-of-line
  886  bindkey "\e[H" beginning-of-line
  887  bindkey "\e1~" beginning-of-line
  888  bindkey "\eH" beginning-of-line
  889  bindkey "\e[0H" beginning-of-line

PS: When I am in the last tab and press Ctrl + pagedown I get ;5~ printed on the screen. Does that give any clue?

3
  • 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?
    – bahamat
    Sep 8, 2011 at 14:46
  • 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.
    – balki
    Sep 8, 2011 at 14:56
  • 1
    I guess in that case I won't suggest ctrl+a & ctrl+e ;-)
    – bahamat
    Sep 8, 2011 at 14:59

5 Answers 5

9

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
3
  • nothing gets printed when I press Ctrl then Home. Nothing happens. Tried changing 0 to O as well.
    – balki
    Sep 9, 2011 at 14:07
  • @balki It's Ctrl+V, not Ctrl. I just realized there was a formatting problem in my answer. May 12, 2017 at 0:15
  • Thanks! :) I am now used to ctrl + a and ctrl +e and vi mode
    – balki
    May 12, 2017 at 0:27
9

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
1
  • 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
    – stwr667
    Mar 10, 2022 at 6:37
7

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
2
  • 1
    This worked for me where the accepted answer did not. Aug 13, 2022 at 3:05
  • @WadeWilliams welcome to stack exchange Oct 9, 2022 at 15:18
6

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.

3
  • Also tested in CentOS + bash - works! Thank you :) Mar 6, 2020 at 10:11
  • +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 Sep 17, 2020 at 19:45
  • So now it wont work in terminals that properly emulate xterm? Or does he have a broken terminfo? Apr 14, 2021 at 14:25
6

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .