Oct 26, 2013

Fixing Home and End keys for both Terminal and Vim in Mac OS X (Snow Lion)

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:

Home \001
End \005
Page Up \033[5~
Page Down \033[6~


Next, add the  following lines to your ~/.vimrc file:

" End
map <C-E> <End>
imap <C-E> <C-O><End>
" Home
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.

No comments:

Post a Comment