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

How do I paste or reuse my last search pattern?

Answer

<C-r>/

Explanation

Vim stores your last search pattern in the / register. You can access it anywhere registers are accepted — in insert mode, command-line mode, or with p in normal mode.

How it works

  • "/ is the search register — it always contains the last search pattern
  • <C-r>/ in insert mode pastes the last search pattern as text
  • :put / pastes the search register on a new line
  • In command-line mode, <C-r>/ inserts the pattern at the cursor

Practical uses

" Use last search in a substitute (empty pattern reuses it)
:%s//replacement/g

" Insert last search pattern as text in your buffer
" (in insert mode)
<C-r>/

" Use in a mapping or command
:let @a = @/    " Copy search pattern to register a

" Print what you last searched for
:echo @/

Example

You search for a regex pattern /\v(\w+)@(\w+\.\w+)/ to find email addresses. Later, you want to document what pattern you used:

  1. Enter insert mode
  2. Press <C-r>/
  3. The pattern \v(\w+)@(\w+\.\w+) is inserted as text

Tips

  • The substitute command :%s//new/g with an empty pattern automatically reuses the last search — this is one of the most efficient Vim workflows
  • Use @/ in Vimscript to access the search register programmatically
  • The search register persists across sessions via viminfo/shada

Next

How do I always access my last yanked text regardless of deletes?