How do I extend a visual selection up to the next search pattern match?
Answer
v/{pattern}
Explanation
Starting a visual selection and then typing / followed by a pattern extends the selection to the next match of that pattern. The selection grows from the starting position to wherever the pattern matches — giving you a flexible way to select irregular ranges without counting lines or columns.
How it works
- Press
vto start character-wise visual mode - Type
/{pattern}<CR>to search — the selection extends to the match - Operate on the selection (
d,y,c,gq, etc.)
Example
Select from the current cursor position to the next def:
v/def<CR>
Now d deletes everything from the cursor to (and including) the word def.
Select from current line to the next blank line:
V/^$<CR>
Tips
- Search direction matters: use
?patternto extend the selection backward - The search still obeys
ignorecase/smartcase— use\Cfor case-sensitive:v/\CPattern<CR> - After selecting, you can refine with
o(toggle which end of the selection the cursor is on) then adjust with more motion keys - This works in all three visual modes:
v(character),V(line),<C-v>(block) - Pair with
:set incsearchto see the selection grow as you type the pattern