How do I extend a visual selection to a search match?
Answer
v/pattern<CR>
Explanation
Starting a search while in visual mode extends the selection to the search match. This is a precise way to select text up to a specific pattern.
How it works
- Enter visual mode with
v - Type
/patternto search forward - The selection extends from the original position to the match
- Press
nto extend further to the next match
Example
function process(data, options, callback) {
With cursor on p in process, press v/callback<CR> to select from process to callback.
Tips
?patternextends backwardnandNadjust the selection to subsequent matches- Combine with operators after selection
d/pattern<CR>deletes to the pattern without visual mode/pattern/eincludes the entire match in the selection