Fixing macOS's terminal Home, End, and Function keys

macOS's defaults for Home, End, and F1-F4 keys have different behaviors than what one would expect coming from a Linux terminal. Instead of moving to the start and end of a line, they scroll the entire terminal window. Fortunately, the Terminal app comes with key mapping built-in. F1-4 function keys are also mapped to some other functions.

To change this,  go to Terminal -> Preferences and click on the Profiles tab. In this tab, on the profile that you wish to use, click on the "Keyboard" tab. Click on the "+" button below the list of keymaps to add mappings for Home and End with the following escape sequences. Note that in the key mapping editor, use the Esc key to enter the starting escape sequence \033. Typing \ will result in an escaped backslash (i.e. \\ ) instead.

  • Home: \033OH
  • End: \033OF
  • F1-4: \033[11~, \033[12~, \033[13~, \033[14~

The function keys should already have a keymap, edit those so that they work as intended in terminal programs. Finally, it might also be useful to check the option below the keymaps "Use Option as Meta key", I do use it for several functions in Vim ( <M-... ).

Don't want to do it yourself? Here's my Terminal profile with the keymaps configured, together with my color scheme.

Show Comments