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:
- Ctrl + ←: to go to the beginning of the word
- Ctrl + Shift + →: to select the whole word
Is there a better way of doing this?
57 Answers
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.
There is a better way. AutoHotkey.
Or if you are in Visual Studios, Ctrl W selects the whole word.
4In 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
This AutoHotKey script maps Ctrl-W to select the word under the cursor:
#IfWinActive ahk_class OpusApp
^W::
SendInput ^{left}+^{right}
#IfWinActiveTested with Word 2010, should work with other versions as well.
0Here 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 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+<
- double click and customise:
- and search
cursorWordStartRightSelect- double click and customise:
cmd+alt+shift+>
- double click and customise:
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