vim – expand the word under the cursor


To search a file in vim, I usually do this:

  1. I press /
  2. I enter the required search pattern – for example, the word function
  3. 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.


The algorithm is as follows:

  1. Hover over a word
  2. Press *
  3. 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.

Scroll to Top