16

What is the keyboard shortcut to select a word that your typing cursor is currently on ?

For example, if the word I want to select is World, while the typing cursor is between one of the letters of that word such as This Wo|rld is huge, what do I press to select only World ?

4 Answers 4

11

I don't know a single shortcut to select the word, but you can do it in two steps, by first moving the cursor to the start of the word, then select the word.

1) Move cursor to left of word:

⌥←

2) Select word to right of cursor:

⇧⌥→

Of course you could do a similar thing with moving to the right of the word with ⌥→ then selecting the word to the left of the cursor with ⇧⌥← if you prefer.

2
  • That is a good substitute.
    – Render
    Mar 9, 2013 at 20:20
  • 3
    omg! why xcode don't have built-in hotkey for such useful action?
    – zxcat
    Feb 19, 2016 at 23:29
11

You could also create ~/Library/KeyBindings/ and save this as DefaultKeyBinding.dict:

{
    "~w" = selectWord:; // option-w
}

You have to reopen applications to apply changes. DefaultKeyBinding.dict doesn't work in Xcode or some cross-platform applications, but you could use KeyRemap4MacBook as a fallback:

<?xml version="1.0"?>
<root>
<item>
<name>Xcode</name>
<identifier>private.xcode</identifier>
<only>XCODE</only>
<autogen>__KeyToKey__ KeyCode::W, VK_OPTION | ModifierFlag::NONE, KeyCode::CURSOR_LEFT, ModifierFlag::OPTION_L, KeyCode::CURSOR_RIGHT, ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L</autogen>
</item>
</root>
3
  • Ahh I actually wanted this feature to be used in Xcode. THanks though.
    – Render
    Mar 10, 2013 at 14:52
  • I'm using the updated version of KeyRemap4MacBook (aka "Karabiner") and couldn't get the XML config to work (OPT-W insists on inserting a greek :sigma: rather than running the macro). However, the DefaultKeyBinding.dict worked fine (OSX Mavericks).
    – 3Dave
    Aug 19, 2014 at 1:05
  • is there a system wide option for this?
    – Andrea
    Apr 22, 2022 at 9:43
8

In the current version of Xcode, you can set up the shortcut in Preferences... ( ⌘, ) -> Key Bindings, filter "select word", then you can choose a new shorcut by typing it in the field "Key" associated

3
  • 1
    Why was this voted down? It works for me with Xcode 9.3.1
    – dnlkng
    May 25, 2018 at 15:34
  • That works! (Xcode uses almost all conceivable key bindings by default, so the challenge is to find one that is available, or pick one to swap:-)
    – rene
    Jun 17, 2018 at 2:29
  • Works with Catalina and Xcode 11
    – craft
    Feb 4, 2020 at 15:14
3
  1. Open Preferences..
  2. Go to Key Bindings > Text tab
  3. Thus it does not provide default shortcut. You have to customize it by setting keys. enter image description here
2
  • which app are these preferences for? I can't find this in system preferences and OP never specified an app
    – BlkPengu
    Jul 3, 2022 at 14:14
  • For XCode @BlkPengu
    – adak
    Jul 5, 2022 at 4:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .