Question:
To search a file in vim, I usually do this:
- I press
/
- I enter the required search pattern – for example, the word
function
- I press
enter
, and then I move on through the search results.
How to exclude item 2 from this list 🙂 Suppose my cursor is on the first letter of the word function
, a combination is required (binding in .vimrc
), which can be pressed – and the word will be automatically added to the search buffer.
Answer:
The algorithm is as follows:
- Hover over a word
- Press
*
- vim advances to its next occurrence.
As KoVadim rightly noted, instead of *
you can use #
, then the search will go in the opposite direction.
Also, there is described a way to find and replace the word under the cursor.