28

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

28

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. Commented 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. Commented May 10, 2016 at 11:54
  • 1
    @PhilippFrank, I'll add this to the answer, thanks Commented May 10, 2016 at 11:54
  • 4
    Related Vimcasts episode: Refining search patterns with the command-line window Commented May 10, 2016 at 14:14
  • 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 Commented Jun 20, 2022 at 12:47
3

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 Commented 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. Commented Jun 3, 2023 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.