vimtricks.wiki Concise Vim tricks, one at a time.

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

  1. Press v to start character-wise visual mode
  2. Type /{pattern}<CR> to search — the selection extends to the match
  3. 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 ?pattern to extend the selection backward
  • The search still obeys ignorecase/smartcase — use \C for 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 incsearch to see the selection grow as you type the pattern

Next

How do I run a search and replace only within a visually selected region?