brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: hidutil remaps Caps Lock to Escape without installing anything

Terminal
~/tips/tip-macos-hidutil-caps-lock-escape

hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}'

Remaps a key on the Mac keyboard from Terminal, until the next restart.

If you press Escape a lot, in Vim or anywhere else, Caps Lock is a much nicer key to reach. System Settings can swap modifier keys, but it does not offer Escape. The built-in hidutil command does.

hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}'

The long numbers are USB usage IDs with the prefix 0x7000000. 0x39 is Caps Lock and 0x29 is Escape, so this maps Caps Lock to Escape. Apple lists the other IDs in Technical Note TN2450.

To see what is active right now:

hidutil property --get "UserKeyMapping"

To undo it, set the mapping to an empty list:

hidutil property --set '{"UserKeyMapping":[]}'

The caveat: Apple’s note says the mapping is not permanent. It is gone after a restart, and also when the last keyboard is disconnected. No special privileges are needed, and it applies to every user while a keyboard is connected. To make it stick you need a launch agent that runs the command at login. I’d only bother with that once you are sure you like the new layout. Until then, the restart is a handy reset if you map the wrong key and cannot type what you meant.

Further reading: Technical Note TN2450: Remapping keys in macOS

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc sudo tmutil restore -v "/Volumes/Backup Disk/Backups.backupdb/My Mac/2026-11-30-120000/Macintosh HD – Data/Users/me/Documents/report.pdf" ~/Desktop/ All Terminal tips (116) All topics

Link