.MacOS Sonoma, Home and End Keys in Terminal and ViM - Chris Stretton

Chris Stretton

Feb 12, 2024

MacOS Sonoma, Home and End Keys in Terminal and ViM

The home and end keys on the MacOS Termianl.app are not set up correctly by default, they instead act as controls for the interface scrollback.

This is fairly simple to change.

In Termainal.app go to Terminal > Settings and select the Profiles tab.

Select your profile of choice and go to the Keyboard tab.

Find the Home (↖) key, and change its value to \001 (by pressing ctrl+a)

Find the End (↘) key, and change its value to \005 (by pressing ctrl+e)

This will make your home and end keys behave as expected in the terminal, however vim still expects the old default xterm bindings.

This can be fixed in ~/.vimrc

Edit your .vimrc file in your editor of choice (presumably vim!) and add the following remap:

1
2
3
4
5
6
map  <C-A> <Home>
imap <C-A> <Home>
vmap <C-A> <Home>
map <C-E> <End>
imap <C-E> <End>
vmap <C-E> <End>

This changes the home and end key maps in all 3 modes (command, insert and visual) to use ctrl+a and ctrl+e for home and end accordingly.

Save and reload vim and your home and end keys should work as expected!

OLDER > < NEWER