How do I view my complete Vim command and search history?
Answer
:history
Explanation
:history displays a numbered list of your recently entered Ex commands, giving you a full audit of what you have run in the current session (and across sessions if viminfo/shada is enabled). It is especially useful when you want to recall a complex substitution or :g command you ran earlier but did not save to a macro.
How it works
:historywith no arguments shows the cmd history (Ex commands like:s,:g,:set)- You can filter by history type:
:history /— search patterns (/and?):history :— same as default, Ex commands:history =— expression register evaluations:history @— input line (e.g.:input()calls):history all— all history types combined
- Each entry has a number you can use to re-execute it
Example
:history
Output:
# cmd history
1 set number
2 %s/foo/bar/g
3 g/TODO/d
> 4 wq
The > marks the most recent entry.
Tips
- Press
<Up>/<Down>at the:prompt to cycle through history without invoking:history - Use
q:to open the command-line window, which shows your history in a buffer you can edit and re-execute with<CR> - The depth of history is controlled by
'history'option (default 200)::set history=1000