One of my favorite features in Sublime Text is the Cmd+D keyboard shortcut that selects the word nearest to your text cursor. Multiple presses select other instances of the word allowing you to edit them simultaneously, but I mostly use it to select the word I just typed.1 A similarly helpful feature has come to the iPad and iPhone 6S in iOS 9.2
Since most of my day is spent in Sublime Text, pressing Cmd+D quickly made its way into my muscle memory, and I started attempting to use it in other programs to no avail. A little bit of searching led me to the discovery that OS X has a similar feature built-in, but it’s not easily assigned to a hotkey.
You’ll need to create ~/Library/Keybindings/DefaultKeyBinding.dict
and add the following lines to it, then restart any open applications you want to use the hotkey in:
{
// ^ for Control, ~ for Option, $ for Shift, @ for Command
"^w" = (selectWord:);
}
The example above uses Ctrl+W, but you can customize it to your liking. For instance, swapping ^w
for @d
would match Sublime Text’s key combination.3
Any application that uses native text fields will now allow you to quickly select the current word. Have fun editing!
-
If you’re interested in editing every instance of the current word, there’s a better way: Cmd+Ctrl+G. ↩
-
iPad: Tap the keyboard with two fingers.
iPhone 6S: Press down hard on the keyboard. ↩ -
Be careful. Unfortunately Cmd+D is set to other actions in a lot of applications, and this won’t override it. For instance, Safari uses it to create a bookmark. You might want to pick something else. ↩