Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the last search or search&replace string back in vim?

How can I bring back the last string I used for a search or a search&replace?

For example, assume that I enter :%s/some_text/some_other_text/gc and vim gives me the E486: Patterns not found: some_text error message back. I then realize that I actually meant to write some_magic_text instead of some_text. At that point, how can I get back my original string in the bottom command row (or whatever it is called) so I can change it and do a second search? Is there a nifty little command for that?

In this brief example it looks unnecessary, but when the text you are looking to replace is mighty long and you just typed one letter wrong, it is fantastically annoying to have to retype everything.

And I am using MacVim if that makes any difference.

like image 497
c00kiemonster Avatar asked Dec 06 '10 01:12

c00kiemonster


2 Answers

From the normal mode, hit q/ to navigate through your search history!

like image 83
Benoit Avatar answered Oct 24 '22 17:10

Benoit


/ and then up to bring up the last search query.

like image 43
webninja Avatar answered Oct 24 '22 18:10

webninja