How do I search only the message part of TODO comments using match boundaries?
Answer
/\vTODO:\s*\zs.{-}\ze\s*($|#)
Explanation
When TODO comments include prefixes, owners, or trailing metadata, a plain search often lands on the wrong part of the line. This pattern uses match boundaries so Vim highlights only the message text, not the TODO: label or trailing marker. It is especially useful when you want to operate on the actionable part of comments with commands like cgn, n, N, or gn.
How it works
/\vTODO:\s*\zs.{-}\ze\s*($|#)
\venables very-magic mode so the pattern is easier to read.TODO:\s*matches the label and optional spaces after it.\zssets the start of the actual match right after that prefix..{-}is a non-greedy match for the message body.\zesets the end of the match before trailing whitespace and metadata.\s*($|#)consumes optional trailing spaces followed by end-of-line or a#marker.
Example
Given:
TODO: tighten retry logic #backend
TODO: clean dead flags
Searching with this pattern selects only:
tighten retry logic
clean dead flags
Tips
- Use
cgnright after this search to edit only the extracted message text. - Replace
TODO:withFIXME:orNOTE:to reuse the same boundary pattern. - Keep
.{-}non-greedy; greedy.*tends to swallow too much text.