Bartosz Radaczyński
Bartosz Radaczyński

Reputation: 18564

Vim using last searched for regex in :s command

I am using slash for searching for stuff within vim. I'd like to use the regex that I used for search in a command (a substitute command to be exact). Is there a simple way to do it?

Upvotes: 6

Views: 284

Answers (2)

Juan Calero
Juan Calero

Reputation: 4214

Use the useful CTRL-R:

In the command line, if you are making a substitute command search with :, you can press CTRL-R and then / to insert the last search into the command line.

It's great that the opposite works too: If you are making a search with the slash, you can add your last command with CTRl-R and then :

Upvotes: 6

heijp06
heijp06

Reputation: 11788

the subtitute command will use the last search if you do not specify it, so just use:

:s//<replacement>

Upvotes: 12

Related Questions