Copy from search mode to ex mode
While in the "/
" mode to search, what should开发者_Python百科 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
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.
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.
精彩评论