If you type q: instead of :q in Normal mode, Vim has not frozen: q: opens the editable command-line window. It is useful for finding, changing, and executing an earlier Ex command, but it can also reveal file names, search terms, and accidentally entered sensitive data. This guide separates the history types first, then provides read-only checks, a non-persistent rehearsal, and privacy stop conditions.
This maintained layer was rewritten in 2026. The 2011 source contains only one observation and a dead HTTP image. Its complete body remains in the inert archive at the end. The archive does not load the old image and is not current operational advice.
Table of Contents
Identify Vim, Neovim, or another vi first
q:, :history, viminfo, and ShaDa are not portable interfaces shared by every classic vi implementation. Start with read-only identification inside the current editor:
:version
:echo has('nvim')
:echo has('cmdline_hist')
:set compatible?
:set history?
has('nvim') returns 1 in Neovim and usually 0 in Vim; has('cmdline_hist') reports whether the build includes command-line history. Launch wrappers, distribution patches, mappings, and plugins may still alter the interface, so use :help cmdline-window and :help :history from the current instance as the final reference.
What q:, q/, and q? open
These keys start in Normal mode:
| Keys | History opened | Direction when executed |
|---|---|---|
q: | Ex command history | Executes the : command under the cursor |
q/ | Search history | Uses the selected pattern for a forward search |
q? | The same search history shared with / | Uses the selected pattern for a backward search |
You can also enter a :, /, or ? command line and press the key configured by 'cedit' to open the corresponding window. In non-compatible Vim, a common default is Ctrl-F. Inspect the current value with :set cedit?; do not assume the terminal or configuration has left it unchanged.
The command-line window opens in Normal mode and can be navigated and edited like a temporary buffer, but it cannot be nested. Editing other historical lines does not rewrite stored history permanently. The line executed with Enter becomes a new history item, just like an ordinarily entered command.
Leave an accidental q: safely
| Goal | Action | Result |
|---|---|---|
| Discard the current line and return to Normal mode | :quit, abbreviated :q | Closes the command-line window without executing the cursor line |
| Execute a line that has been reviewed | Enter | Closes the window and runs that command or search |
| Return the selected line to the command line for inspection | Ctrl-C | Returns to Command-line mode with that line prefilled; it does not discard it |
If you do not know what the cursor line will do, do not press Enter. Do not use :qall! to close this small window either; that can exit the entire editor and discard changes in other buffers. Pressing Esc alone is a Normal-mode action, not a reliable close operation.
Macro recording is another easy state to confuse with this one: q{register} starts recording in Normal mode, and q stops it. The official help says that while recording is active, the q in this sequence stops recording instead of opening the command-line window. Check the status display before repeating keys in an unknown mode.
Recall commands without opening a window
On the command line, Up and Down find older or newer entries matching the prefix already typed. For example, type :set and then press Up to favor an earlier command beginning with set. Shift-Up/PageUp and their downward counterparts ignore the prefix; some terminals do not transmit these key combinations correctly.
Ctrl-P and Ctrl-N normally retrieve an older or newer command without using the current prefix. When command-line completion is already active, they may instead cycle completion candidates. These are key sequences, not literal text to paste and execute:
:set<Up>
:<C-P>
:<C-N>
Read-only inventory with :history
Vim and Neovim divide command-line data into five histories. / and ? use the same search history:
:history :
:history /
:history =
:history @
:history >
:history all
| Name | Contents |
|---|---|
cmd or : | Ex commands |
search, /, or ? | Search strings |
expr or = | Expression-register history |
input or @ | Lines entered through input() |
debug or > | Debug commands |
:history only displays entries; it does not execute them. Its output can nevertheless expose project paths, search terms, or credentials. Do not run :history all during a public stream or paste it into an issue or log without redaction.
Do not confuse four kinds of “history”
| Need | Correct entry point | Difference from q: |
|---|---|---|
| Earlier commands or searches | :history, q:, q/, q? | The subject of this guide |
| Editor messages | :messages | Warnings and output, not an Ex command list |
| The current buffer's undo tree | :undolist and the undo help | Text state, not command-line history |
| Macro, deleted, and copied text | :registers | Register data; q{register} records a macro |
The last three can also contain sensitive text. In particular, do not publish a complete :registers listing merely to diagnose a problem. :undolist is read-only, but :earlier, :later, and undo commands change the selected text state; save or back up before using them.
Cross-session persistence and privacy
'history' controls the maximum number of entries held in each in-memory history. Vim can write commands, searches, input, registers, marks, and other state to viminfo; Neovim's corresponding MessagePack file is ShaDa. Inspect configuration without replacing your settings with someone else's option string.
Vim:
:set history?
:set viminfo?
:set viminfofile?
Neovim:
:set history?
:set shada?
:set shadafile?
On exit, in-memory information is normally merged with the existing state file, and multiple instances may write at different times. Editing or deleting that file directly, or calling histdel(), is destructive and cannot retract a secret already copied into backups, sync services, terminal recordings, shell history, or another editor instance.
Never type passwords, access tokens, or private keys into an Ex command, search pattern, expression, or input(). If a secret has appeared, revoke or rotate it at the issuer first. Then inspect every instance, viminfo/ShaDa file, backup, and log under an approved incident-response process. Hiding the visible entry is not credential remediation.
Do not read an untrusted viminfo or ShaDa file. Vim's official documentation specifically notes that processing untrusted viminfo can involve expression data. Neovim ShaDa should likewise be treated as editor state, not as an arbitrary text snippet to import.
Rehearse in a non-persistent session
From a shell, launch an empty session that reads neither personal configuration nor a persistent history-state file:
vim -N -u NONE -U NONE -i NONE
nvim --clean -i NONE
The first command is for Vim and the second for Neovim. Skip whichever program is not installed. NONE after -i is uppercase and means that viminfo or ShaDa is neither read nor written. This isolation does not disable the terminal's own logging, screen capture, or operating-system auditing.
Run this no-file-write rehearsal in the empty session:
:echo 'history-demo'
:history :
q:
Find the echo line in the window. After reviewing it, Enter can execute it again; if the goal is only to practice leaving, type :quit. Finally exit normally while no file is being edited. This verifies the current version's key semantics without touching personal history.
Evidence to collect when behavior differs
These diagnostics are read-only. :verbose nmap q can reveal a configuration path containing a user name, so redact it before sharing:
:version
:echo has('cmdline_hist')
:set compatible?
:set cedit?
:set history?
:verbose nmap q
Use the evidence to decide:
q:does nothing: confirm Normal mode, macro-recording state, anyqmapping, and whether the build has+cmdline_hist.Ctrl-Fdoes not open the window: inspect'cedit', terminal key transmission, and command-line mappings.- History is empty after restart: inspect
'history', viminfo/ShaDa settings,-i NONE/--clean, an ephemeral container HOME, file permissions, and exit errors. - History differs from expectations: check multiple editor instances, plugin-owned histories, remote sessions, and different user environments; do not immediately overwrite the state file.
- The UI differs: a Neovim frontend or plugin may replace the command-line UI. Reproduce with
--clean -i NONEto separate core behavior from configuration.
Bounded checklist
- Record product, version, and features with
:version; do not assume Vim behavior is standard vi behavior. - Use
:quitto leave an accidentalq:; review the cursor line character by character before executing it. - Limit output with
:history {type}and redact it before public sharing. - Inspect persistence through read-only
:set ...?; do not overwrite the complete viminfo/ShaDa option string. - Reproduce mapping or plugin problems in a clean
-i NONEsession. - Rotate any sensitive value that entered history; deleting an entry does not undo disclosure.
References
- Vim: command-line editing, `:history`, and the command-line window
- Vim user manual: command-line history
- Vim options: `'history'`, `'viminfo'`, and `'viminfofile'`
- Vim startup and viminfo security
- Neovim: command-line window and history
- Neovim: ShaDa persistence
- POSIX.1-2024: `vi`
- Vim: undo and the undo tree
Historical source archive
The following is the complete inert archive of the visible 2011 body in source_export. The source has no trailing whitespace and contains no private or tracking value requiring redaction, so nothing was replaced. The dead HTTP image address remains only as source evidence and cannot load inside the code fence.
用vi/vim的时候总是会误把命令历史调出来。原来把“:q”打成了“q:”。

