Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim, how to search by current word under cursor?

Tags:

vim

For example

  test test word

Currently the cursor is under word, and I want to search by word, normally I would do select word and copy it. then type :/ and paste and return.

Is there any shortcut for this?

like image 912
vego Avatar asked Nov 19 '19 05:11

vego


People also ask

How do I select current word in vim?

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

How do I cycle through a search in vim?

Press Esc to cancel or press Enter to perform the search. Then press n to search forwards for the next occurrence, or N to search backwards. Type ggn to jump to the first match, or GN to jump to the last.

How would you search for a particular string upwards downwards in vi editor?

To find a character string, type / followed by the string you want to search for, and then press Return. vi positions the cursor at the next occurrence of the string. For example, to find the string “meta,” type /meta followed by Return. Type n to go to the next occurrence of the string.


1 Answers

Use * to search forward and # to search backward, for the word under the cursor. Once you initiate the search, you can use n to repeat it in the same direction or N in the reverse direction. Or else use * or # again from the word that you landed on.

The * and # commands basically initiate searches as if you used /\<word\> or ?\<word\>. Thus these searches can be recalled with up arrow at the / or ? search prompt.

like image 122
Kaz Avatar answered Sep 22 '22 12:09

Kaz