42

Suppose that I'm writing some text and the caret is in the middle of a word. I would like to be able to select that word without using my mouse. (Using the mouse, simply double-click on the word.)

I have found the following, but it's kind of clunky:

  1. Ctrl + : to go to the beginning of the word
  2. Ctrl + Shift + : to select the whole word

Is there a better way of doing this?

5
  • 2
    I think this is the simplest way to do it without a mouse. It's only 2 steps.
    – bwall
    Oct 14, 2011 at 14:57
  • 3
    It depends on what program you're in. Many editors would have a keystroke for select current word.
    – Julian
    Oct 14, 2011 at 15:01
  • @Julian: I'm mostly in Google Chrome, I guess.
    – Randomblue
    Oct 14, 2011 at 15:29
  • 2
    You don't have to release CTRL key between step 1 & 2. So you can reduce one more key stroke, if you're not doing this yet.
    – Scott Rhee
    Jun 1, 2015 at 5:09
  • The question and the answers here are not smoothly, because the space at the end of the selected word is also selected, which should be avoided in my opinion. At least you should mention this obstacle in the question.
    – mouwsy
    Apr 5, 2022 at 10:12

7 Answers 7

18

On macOS, create a file ~/Library/KeyBindings/DefaultKeyBinding.dict with the following content:

{
    "^w" = (selectWord:);
}

If the file already exists, add the second line above within its top-level braces.

Restart (quit and start again) an app to apply new key bindings.

Now you can press ^w (Control-W) in any native application (i.e. not Firefox, Eclipse, etc.) to have it select the current word.

You can customize the shortcut, ^ is Control, ~ Option, $ Shift, @ Command.


Some applications include menu items for this action. TextMate, for example, uses the ^w shortcut for Edit » Select » Word by default.

9
  • 2
    This works with Google Chrome.
    – Daniel Beck
    Oct 14, 2011 at 17:53
  • Great. Thanks.. Works for me.. Ctrl + w Aug 29, 2015 at 6:07
  • I would only add a few remarks for this great answer: directory is KeyBindings if you have a case-sensitive file system, and you should restart apps to apply new key bindings.
    – rshev
    Apr 29, 2016 at 9:28
  • 1
    @rshev That's what suggested edits are for, give it a try ;-)
    – Daniel Beck
    Apr 29, 2016 at 9:39
  • What does On OS X, mean? Say I have Windows 10; What exactly do I have to do?
    – MJH
    Dec 19, 2017 at 8:00
19

There is a better way. AutoHotkey.

http://www.autohotkey.com/

Or if you are in Visual Studios, Ctrl W selects the whole word.

4
  • 1
    How'd you configure AutoHotkey to make this work?
    – Daniel Beck
    Oct 18, 2011 at 17:53
  • 1
    +1: Excellent, for some reason I half-expected Ctrl + W to close the window I was working in in MSVC. But that's Ctrl + F4. In many other applications, Ctrl + W does just that though (closes the active window), so it seems a little dangerous to use AutoHotkey to make this shortcut work globally - maybe that's just paranoid old me? Sep 1, 2015 at 5:41
  • Without a authotkey code, this answer is pretty unhelpfully.
    – mouwsy
    Apr 5, 2022 at 10:06
  • In Visual Studio, my default binding was Ctrl+Shift+W. Those bindings are at Tools->Options->Environment->Keyboard and the command name is 'Edit.SelectCurrentWord'
    – StevoInco
    Apr 12, 2022 at 21:07
7

In MSWord, press F8 once to enter the extended mode, twice to select the whole word, three times to select the whole sentence, four times to select paragraph and five times the entire document. Press ESC to exit the extended mode

2

This AutoHotKey script maps Ctrl-W to select the word under the cursor:

#IfWinActive ahk_class OpusApp
^W::
SendInput ^{left}+^{right}
#IfWinActive

Tested with Word 2010, should work with other versions as well.

0
2

Here is a more efficient key sequence to send with Autohotkey. It will work both when the cursor is inside a word and when it is just before the first letter or just behind the last letter. Should work globally in Windows:

^w::
    SendEvent +{Right}^{Left}+^{Right}
    if (WinActive("ahk_class OpusApp"))
    Send +{Left}
return
1

Visual Studio Code

If you'd like the keybindings to match another editor: (left/right) arrows to select a whole word. In my instance: cmd+alt+shift+< or cmd+alt+shift+>, for example, do the following in VSC:

  • edit keyboard shortcuts
  • search select word
  • delete the keybindings you don't need (you might need to experiment to achieve the exact behaviour you're looking for).
  • search cursorWordStartLeftSelect
    • double click and customise: cmd+alt+shift+<
  • and search cursorWordStartRightSelect
    • double click and customise: cmd+alt+shift+>
0

The first answer was right. Do Ctrl+rightarrow then do Ctrl+Shift+leftarrow. To make this shorter, save this in a Macro. Just record those keystrokes in word and give the macro a simple keyboard shortcut like, say, Ctrl+D (D reminds me of double click).

The text of the macro in visual basic is:

Sub SelectWord()
'
' SelectWord Macro
'
'
    Selection.MoveLeft Unit:=wdWord, Count:=1
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
End Sub

You must log in to answer this question.

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