How do I open the command-line window while I am already typing a command?
Answer
<C-f> (command-line mode)
Explanation
Pressing <C-f> while in the command-line (:, /, or ? prompt) opens the command-line window with your partially-typed command already loaded and ready for full Vim editing. This is the mid-typing equivalent of q: (or q/) from Normal mode.
How it works
- You start typing a complex command, e.g.
:%s/foo/bar/ - You realize you want to use Vim motions to edit it more carefully
- Press
<C-f>ā a new window opens containing the command-line history, with your in-progress command at the bottom - Edit it with the full power of Vim (motions, operators, registers)
- Press
<CR>on the line you want to execute, or:qto cancel
Example
Typing: :%s/very-long-pattern-you-misspelled/
ā press <C-f>
Opens the command-line window with:
:%s/very-long-pattern-you-misspelled/
You can now use F- to jump to the hyphen, cw to fix the typo, and <CR> to run it.
Tips
<C-f>from/or?mode opens the search history window insteadq:opens the command-line window from Normal mode (history only, no in-progress command):qor<C-c>closes the command-line window without executing