18

If you search something in Vim by prepending searchterm with a forward slash, e.g. /searchterm, Vim puts that searchterm into the search string history table. You then are able to navigate through past search terms by typing in forward slash (/) and using Up/Down arrow keys.

That search string history table is persistent across Vim restarts.

Everything above is also true for command (typed with : prepended) history table.

How do I clear those history tables?

2 Answers 2

26

The history is persisted in the viminfo file; you can configure what (and how many of them) is persisted via the 'viminfo' (and 'history') options.

You can clear the history via the histdel() function, e.g. for searches:

:call histdel('/')

You can even delete just certain history ranges or matching lines.

Alternatively, you could also just edit the ~/.viminfo file directly (when Vim is closed, and either with another editor, or with vim -i NONE).

1
  • 1
    :call histdel(":") deletes the entire command history. Use :call histdel(":", "expr") to delete entries matching an expression. Oct 18, 2020 at 5:04
0

Edit ~/.viminfo go to section # Search String History and remove the lines that you whish to not appear to search history. Unlike histdel() these changes are permanent.

1
  • If you use vim to edit ~/.viminfo directly, you may want to page through the file and search for offending strings visually. Because, any / search you do will just end up going back into the file.
    – RichieD
    Oct 14 at 22:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .