Terminal.app
Enter “Terminal->Preferences->Settings->Keyboard“, and change the following options (press <ESC>
to get \033
in text below):
Vi Mode
Home: \033[H End: \033[F PageUp: \033[5~ PageDown: \033[6~
Emacs Mode
Home: \033[1~ End: \033[4~ PageUp: \033[5~ PageDown: \033[6~
Bash/Readline
Edit your ~/.inputrc and add the following lines:
Common settings
# Be 8 bit clean. set input-meta on set output-meta on set convert-meta off # allow the use of the Delete/Insert keys "e[3~": delete-char "e[2~": quoted-insert # mappings for "page up" and "page down" # to step to the beginning/end # of the history "e[5~": beginning-of-history "e[6~": end-of-history
Vim mode settings
# Vi mode set editing-mode vi set keymap vi # allow the use of the Home/End keys "e[H": beginning-of-line "e[F": end-of-line
Emacs mode settings
# allow the use of the Home/End keys "e[1~": beginning-of-line "e[4~": end-of-line
Vim
Edit the file ~/.vimrc and add the following options:
Terminal configured with Vi mode
map <Esc>[H <Home> imap <Esc>[H <Home> map <Esc>[F <End> imap <Esc>[F <End> map <Esc>[5~ <PageUp> imap <Esc>[5~ <PageUp> map <Esc>[6~ <PageDown> imap <Esc>[6~ <PageDown>
Terminal configured with Emacs mode
map <Esc>[1~ <Home> imap <Esc>[1~ <Home> map <Esc>[4~ <End> imap <Esc>[4~ <End> map <Esc>[5~ <PageUp> imap <Esc>[5~ <PageUp> map <Esc>[6~ <PageDown> imap <Esc>[6~ <PageDown>
Cocoa Keybindings
Put the following lines in ~/Library/KeyBindings/DefaultKeyBinding.dict:
{ /* home */ "UF729" = "moveToBeginningOfLine:"; "$UF729" = "moveToBeginningOfLineAndModifySelection:"; /* end */ "UF72B" = "moveToEndOfLine:"; "$UF72B" = "moveToEndOfLineAndModifySelection:"; /* page up */ "UF72C" = "pageUp:"; "$UF72C" = "pageUpAndModifySelection:"; /* page down */ "UF72D" = "pageDown:"; "$UF72D" = "pageDownAndModifySelection:"; }
Firefox
Install the following Firefox extension.
Textmate
I strongly recommend to Textmate users to disable the “Smooth Scrolling” option in System Preferences->Appearance->Use smooth scrolling. This option cause a strange behaviour with Page Up/Down on Textmate.
References
- http://serverfault.com/questions/73013/vim-keyboard-remap-on-snow-leopard-macos-10-6/73248#73248
- http://tech.inhelsinki.nl/gnu_developement_under_mac_os_x/
- http://heisencoder.net/2008/11/keyfixer-04-for-firefox-and-thunderbird.html
- http://fdiv.net/2007/05/12/keybindings-in-macosx-terminal-app/
- http://blog.macromates.com/2007/leopard-issues/
Update: Added suggestion to disable “Smooth Scrolling” for Textmate users.