Multiple posts on the Internet describe ways to fix Home, End, Page Up and Page Down buttons in OS X Terminal application, which don’t work there by default. While this particular post helped me fix these shortcuts for the Terminal itself, Home and End still didn't work in Vim, especially in the INSERT mode. After going through several posts and comments I found the sequence that worked for both. Here are my results.
First, follow these steps to fix Home, End, Page Up and Page Down in the Terminal itself. Below are the codes you should end up with for the Terminal:
Next, add the following lines to your ~/.vimrc file:
map <C-E> <End>
imap <C-E> <C-O><End>
map <C-A> <Home>
imap <C-A> <C-O><Home>
Restart all Terminal and Vim instances, and Home and End buttons should work in both.