How do I search non-greedily across multiple lines between two markers?
/\vstart\_.{-}end
Multiline searches in Vim often overmatch because .
/\vstart\_.{-}end
Multiline searches in Vim often overmatch because .
/\vTODO:\s*\zs.{-}\ze\s*($|#)
When TODO comments include prefixes, owners, or trailing metadata, a plain search often lands on the wrong part of the line.
/foo\@<!bar
Vim regex supports zero-width assertions, so you can match text based on context without consuming the context itself.
/\%>20l\%<40lTODO
Vim's search engine can constrain matches by line number, which is useful when you want to scan a known section without touching the rest of the buffer.
:execute 'vimgrep /' . @/ . '/gj **/*'
If you already refined a search interactively with / or ?, retyping that pattern for project-wide grep is repetitive and error-prone.
:psearch /pattern/
When you need quick context from another file but do not want to disturb your current editing window, :psearch gives you a clean workflow.
buffers-windows #buffers #windows #preview-window #search #navigation
:packadd cfilter | Lfilter /pattern/
When you already have a populated location list, rerunning the original search just to focus on a subset is slow and disruptive.
:lgrep /pattern/ % | lopen
Quickfix is global, but sometimes you want a narrower search workspace tied to one window.
:let @/ = '\V' . escape(@0, '\')
When the text you yank contains regex characters, a normal / search can produce noisy or surprising matches.
:%s/pattern/replacement/gn
When you are about to run a broad substitution, it is often safer to measure impact first.
command-line #command-line #ex-commands #substitution #search
/\v<(TODO|FIXME|BUG)>
When you triage code, jumping among TODO, FIXME, and BUG markers quickly is often more useful than searching each token separately.
:let @/ = '\V' . escape(expand('<cword>'), '\')
This pattern lets you prepare a precise search target without jumping the cursor or triggering an immediate search motion.
:let @/ = '\V' .. escape(expand('<cword>'), '\\')
Sometimes * is too opinionated: it uses keyword boundaries and interprets regex metacharacters.
:lvimgrep /\<TODO\>/gj **/* | lopen
If you want project-wide search results without polluting the global quickfix list, use a location list.
*Ndgn
When you are reviewing repetitive text, you often need to remove one specific match without running a broad substitute.
:ldo s/foo/bar/ge | update\<CR>
:ldo is one of the most effective ways to perform targeted, multi-file edits without touching unrelated text.
:lvimgrep /TODO/j **/* | lopen\<CR>
When you are working in multiple windows, quickfix can become noisy because it is shared globally across the editor session.
:g/./t.\<CR>
The :global command can apply an Ex action to every line that matches a pattern.
:lvimgrep /pattern/j **/* | lopen
Quickfix is great, but it is global.
:lvimgrepadd /pattern/gj **/*
When investigating a bug or refactor, you often need to gather results from several related patterns before deciding what to edit.