Go to the next word in Vim without using a search

Is there a shortcut in Vim to go to the next word that matches the word cursor? It should work without entering a word with the search / command.

+7
source share
5 answers

* goes to the next matching word, and # goes to the previous matching word. * so useful that it is sometimes called a super star.

+18
source

* and # are your friends (forward and backward respectively)

+6
source

To search for the current word under the cursor, use '*'.

to search back for the current cursor word use '#'

+5
source

Although all the answers here are correct, I thought it might be helpful to provide a little more information.

What * does really * is to do a direct search for \<word-under-the-cursor\> . Since this is just a search operation, you can move back and forth to the next occurrences using n and n . It also means that your previous search is lost. # exactly matches * , except that it does reverse lookups.

\< and \> in the search bar are the word boundaries in the regex vim language, which makes the job so enjoyable. It is also important to note that what is considered a โ€œwordโ€ is determined by the iskeyword option. See :help word details.

+4
source

gd and its variants are also very convenient. It works a little differently than * because it searches for a local word declaration under the cursor (or a global declaration if none of the local ones exists). Then you can view the results with n , as you can, with a superstar, and he will skip the comments. This can be useful when editing code.

 :help gd 
+2
source

All Articles