People all over the internet complain about Apple’s (incorrect) mapping of the Home, End, Page Up, and Page Down keys. I spend a lot of time in the terminal and in vim, and it’s important to me that these keys function properly. Here’s what I needed to do in order to get these keys working properly in the terminal and in vim:

  1. Open up the terminal preferences.
  2. Go to the Settings tab, and select the desired profile.
  3. Go to the profile’s Keyboard tab.
  4. Add (or edit) the Home key so that it sends this text to the shell: \033OH
  5. Add (or edit) the End key so that it sends this text to the shell: \033OF
  6. Add (or edit) the Page Up key so that it sends this text to the shell: \033[5~
  7. Add (or edit) the Page Down key so that it sends this text to the shell: \033[6~

There are some other commonly recommended sequences (e.g., \033[1~ instead of \033OH), but the sequences above are the only sequences I’ve found that work in both the terminal and vim.