How do I browse and edit my backward search history in a full Vim buffer?
Answer
q?
Explanation
Vim provides three command-line history windows accessible from normal mode: q: for Ex commands, q/ for forward searches, and q? for backward searches. Pressing q? opens the ? search history as a regular Vim buffer where you can navigate, edit, and re-execute previous backward searches using the full Vim editing vocabulary.
How it works
q:— opens Ex command history as a Vim bufferq/— opens forward (/) search history as a Vim bufferq?— opens backward (?) search history as a Vim buffer- Inside the history window: navigate with
j/k, edit with any motion or operator, press<CR>to execute the line as a new backward search, close with:qor<Esc> - The most recent entry appears at the bottom of the buffer
Example
You've been searching backward with ?TODO, ?FIXME, ?class. Pressing q? opens:
TODO
FIXME
class
Navigate to TODO, edit it to TODO: with A:<Esc>, then press <CR> to run ?TODO: as a new backward search — without ever retyping the pattern.
Tips
- From inside command-line mode (already typing
?), press<C-f>to open the same history window mid-command - Use
Gto jump to the last (most recent) entry in the history buffer - History buffers are unlisted (
unlistedflag); they do not appear in:lsoutput - Both
q/andq?share the same underlying mechanism (cmdwin); see:help cmdwinfor full details - The history window is a real buffer: use
/inside it to search your search history