views:

61

answers:

2

While in the "/" mode to search, what should I do if need to copy it to the ex mode. E.g. I searched for /ab.*xy, now I need it as %s/ab.*xy/.../g.

My intention is to test my search and then use that for a search replace

+6  A: 

Use the / register, in ex mode press:

Ctrl-R/

Ctrl-R allows you to insert the contents of a register, and the / register contains the last search pattern used.

CMS
awesome! works like a charm.
Quintin Par
That's pretty sexy.
Pierre-Antoine LaFayette
+4  A: 

Alternatively, you can leave the search portion blank:

:/foo
:s//bar

The first line finds "foo", as you'd expect. Since you left off the search string in the second line, it just re-uses the same search, replacing "foo" with "bar". I believe this works anywhere you type a search string -- if it's blank, that means re-use the previous search.

Alex Martini