vimtricks.wiki Concise Vim tricks, one at a time.

How do I search through command history and only see commands that start with what I've already typed?

Answer

<Up>

Explanation

In Vim's command line, <Up> and <Down> navigate history in prefix-filtered mode — they only cycle through past commands that begin with whatever you have already typed. This is distinct from <C-p> and <C-n>, which scroll through the entire command history with no filtering.

How it works

  • Type a partial command on the command line (e.g., :set )
  • Press <Up> — Vim walks backwards through history and shows only entries that start with :set
  • Press <Down> to move forward through those filtered results
  • Typing nothing before pressing <Up> behaves the same as <C-p> (no filter)

This makes it fast to re-run a specific class of commands. For example, after a long session you can type :e and press <Up> to cycle through only the files you recently opened.

Example

:vimgrep /foo/ **/*.go   " ran earlier
:set hlsearch            " ran earlier
:vimgrep /bar/ src/      " ran earlier

Typing :vimgrep and pressing <Up> cycles between the two vimgrep commands, skipping :set hlsearch entirely.

Tips

  • Use <Up> when you remember the command prefix but not the full command
  • Use <C-p> / <C-n> when you want to scroll through all history regardless of prefix
  • This filtering also applies to search history: in / mode, <Up> cycles through previous searches that start with what you've typed
  • The command-line window (q:) offers even more powerful history browsing with full Vim editing

Next

How do I enable LSP and treesitter-powered code folding in Neovim with nvim-ufo?