Vim command: how to select a word under cursor in normal mode

VimMacvimXvim

Vim Problem Overview


I'm looking for a Vim command to select a word under cursor in normal mode, like double-clicking by mouse. Does it exist like this?

Vim Solutions


Solution 1 - Vim

You can use * and/or # to search for the word under the cursor or viw to visually select the word under the cursor.

Solution 2 - Vim

viw does a visual select inside the word. Similarly yiw copies (yanks) the word.

Solution 3 - Vim

Personally, I am prefering vaw, yaw instead of viw or yiw as a indicates around.

On the similar lines. I use

vat to select tag. va( or va{ v% to select matching closing tag. In some other places ev%

It is making more sense to me as the intention is to select the complete word not inside.

At the end, it all comes down to our personal preference.

Solution 4 - Vim

To select a word under a cursor I use the combination of bve

Be aware though that if the cursor points to a first character you just need ve combination.

Solution 5 - Vim

After using *, if you want to use the text in a command you can do the <C-r> <C-w> trick too (after pressing : or your equivalent).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKeitaView Question on Stackoverflow
Solution 1 - VimpfnueselView Answer on Stackoverflow
Solution 2 - VimMatthew StrawbridgeView Answer on Stackoverflow
Solution 3 - VimAbibullah RahamathulahView Answer on Stackoverflow
Solution 4 - VimFupslotView Answer on Stackoverflow
Solution 5 - Vimt56kView Answer on Stackoverflow