I switched to Catalina and enabled ZSH now my home/end key do not work in terminal

I switched to ZSH from BASH as per the upgrade in Catalina and all is well except my home/end keys no longer work. This can be really annoying trying to move my cursor over super far to the left instead of a single home click.

Any idea if they just changed the key you use to "go to start of command" instead of home? Or is there a bug?


Solution 1:

The other answers didn't work for me when connecting over SSH to the Mac. I had to add the following lines to my ~/.zshrc to get Home and End to work:

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

Solution 2:

It seems the control characters required for zsh in Terminal are slightly different than the ones that worked in bash.

To fix your Home/End keys:

  1. Open Terminal -> Preferences...
  2. Select your preferred profile
  3. On the Keyboard tab, add a new binding (or modify an existing one)
  4. Use the following settings to make Home work again:
    • Key: Home (↖)
    • Modifier: None
    • Action: Send Text
    • Text to send is \033[1~ (For bash, \033OH was the value that worked)
  5. Use the following settings to fix the End key:
    • Key: End (↗)
    • Modifier: None
    • Action: Send Text
    • Text to send is \033[4~ (For bash, \033OF was value that worked)

This fixes my Home/End keys in zsh, and also works correctly when connected over SSH to terminals running bash.

Note that if you have keybindings specified in your ~/.zshrc or are running a third-party software to adjust your keybindings globally (eg: Karabiner), you might need to check or undo any settings in those places that may affect the Home/End keys if you're getting weird behaviour.

Solution 3:

@jemcclin's answer did not work for me. Here's what worked for me on latest macOS Catalina 10.15.5

  1. Open Terminal -> Preferences...

  2. Select your preferred profile

  3. On the Keyboard tab, add a new binding (or modify an existing one)

  4. Use the following settings to make Home work again:

    • Key: Home (↖)
    • Modifier: None
    • Action: Send Text
    • Text to send is \001 (CTRL+A)
  5. Use the following settings to fix the End key:

    • Key: End (↗)
    • Modifier: None
    • Action: Send Text
    • Text to send is \005 (CTRL+E)

Extra: btw, i was having the same Home/"Scroll to top" issues on webpage forms (like the one i'm typing right now to answer this) and what fixed for me was this

https://www.iexplain.org/remap-home-and-end-buttons-for-external-keyboard-on-mac/