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: Vim's :vimgrep searches many files and :copen lists the hits

Vim
~/tips/tip-vim-vimgrep-quickfix

:vimgrep /TODO/ **/*.py

Searches a whole project from inside Vim and jumps through results.

To find every place a function is used across a project, I’d stay in Vim. :vimgrep searches files and fills the quickfix list.

:vimgrep /TODO/ **/*.py
:copen

The pattern goes between slashes and uses normal Vim regex syntax. **/*.py means every Python file in this folder and all folders below it. Vim jumps to the first match, and :copen opens a window that lists all of them with file name, line and text.

Press Enter on a line in that window to go there. From anywhere, these walk through the list:

:cnext
:cprev

Add j after the pattern, as in :vimgrep /TODO/j **/*.py, if you’d rather not jump to the first match straight away.

The quickfix list is useful beyond searching. :cdo s/old/new/ | update runs a substitute on every line in the list, which makes for a careful project wide rename.

Because :vimgrep loads each file into Vim, it is slow on big trees and searches node_modules as happily as your code. For large projects :grep is faster, since it calls an external program (set grepprg to rg --vimgrep if you have ripgrep) and fills the same list.

Further reading: Vim help: :vimgrep, Vim help: :copen

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