27

We can retrieve search and replace history on IDEs and text editors.

Likewise is there a search history or a way to retrieve previously searched expression in Vim?

Vivian De Smedt
  • 16,336
  • 3
  • 18
  • 37
vusan
  • 381
  • 5
  • 9

3 Answers3

27

Yes, you have the history command:

:history /

Note that it can be used for /, :, =, >, ?, @, all, cmd, debug, expr, input and search.

Alternatively you can use the q:, q/ and q? commands to see previously entered commands and searches on a sepearate buffer. You can then modify as you want and replay them by pressing <CR>.

See :h :history, :h q:.

muru
  • 24,838
  • 8
  • 82
  • 143
nobe4
  • 16,033
  • 4
  • 48
  • 81
2

Just hit / and then Ctrl-f to bring up the search history directly under your cursor, scroll with motion keys and Enter at whichever phrase you need to return to. Since I discovered that Ctrl-f list I've never used awful distant Arrow keys to scroll over.

bloody
  • 140
  • 8
  • Also q/, q:, etc., mentioned in the accepted answer – D. Ben Knoble May 29 '23 at 12:29
  • @D.BenKnoble Yes, q/ is the same and even simpler. The only benefit of Ctrl-f is when you're already in the search mode / (or other mode) and want to bring up the history. Anyway thank you for the indication. – bloody Jun 03 '23 at 17:39
2

You can use :history s for search history. As a shortcut, you can use :his s. Same way for command line history also.

SibiCoder
  • 3,372
  • 5
  • 20
  • 40