brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: * in Vim searches for the word under the cursor

Vim
~/tips/tip-vim-star-search

*

Jumps to the next place a word appears without typing it.

To find where a variable is used next, you don’t need to type a search. Put the cursor on it and press *.

*
#

* searches forward for the word under the cursor, # searches backward. They match whole words only, so on count it won’t stop in counter. After that, n and N continue the search like after any other.

When you do want partial matches, there are variants without the word boundaries:

g*
g#

The word also becomes the last search pattern. So * followed by :%s//total/g replaces every whole word count with total: an empty pattern in :s reuses the last search. I find that a lot quicker than typing the word with \< and \> around it.

With :set hlsearch every match lights up as well, and :nohlsearch clears the highlighting until the next search.

Watch out with ignorecase: * follows it, but it ignores smartcase. So with both set, * on Count still finds count.

Further reading: Vim help: star

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Vim tips :%s/<Ctrl-r><Ctrl-w>/newname/g /oldname find . -name "*.conf" | vim – vim --clean file.txt :set textwidth=72 All Vim tips (45) All topics

Link