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?

3 Answers 3

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:.

5
  • 1
    Thanks. Previously I tried just :history which was bit closer.
    – vusan
    May 10, 2016 at 11:53
  • 4
    As for replace, one can look at q:. It's not exclusive to replaces, but it's a real buffer, so all of vim's power works there. May 10, 2016 at 11:54
  • 1
    @PhilippFrank, I'll add this to the answer, thanks
    – nobe4
    May 10, 2016 at 11:54
  • 4
  • 1
    This answer works great- if you want fast/fuzzy search through your search/command history, you can also use :History/ and :History: using the fzf plugin
    – bricoletc
    Jun 20, 2022 at 12:47
2

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

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.

2
  • Also q/, q:, etc., mentioned in the accepted answer
    – D. Ben Knoble
    May 29, 2023 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 3, 2023 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.