Skip to content

Instantly share code, notes, and snippets.

@alhafoudh
Created April 12, 2026 19:54
Show Gist options
  • Select an option

  • Save alhafoudh/d75c3a22e230b931347bf3210a5b888a to your computer and use it in GitHub Desktop.

Select an option

Save alhafoudh/d75c3a22e230b931347bf3210a5b888a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Setup macOS key mappings for terminal and Cocoa apps
# ~/.inputrc — readline key bindings (bash, etc.)
cat > ~/.inputrc << 'EOF'
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": history-search-backward
"\e[6~": history-search-forward
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
"\e[1;5D": backward-word
"\e[1;5C": forward-word
"\e[Z": menu-complete
set expand-tilde off
set convert-meta off
set input-meta on
set output-meta on
set show-all-if-ambiguous on
set visible-stats on
EOF
# ~/Library/KeyBindings/DefaultKeyBinding.dict — Cocoa text fields
mkdir -p ~/Library/KeyBindings
cat > ~/Library/KeyBindings/DefaultKeyBinding.dict << 'EOF'
{
/* Remap Home / End keys to be correct */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */
}
EOF
echo "Done. Restart apps for DefaultKeyBinding.dict to take effect."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment