How do I open the command-line window mid-command to edit it with full Vim capabilities?
Answer
<C-f> (in command-line mode)
Explanation
When you're already on the Vim command line and realize you need complex edits — inserting text from multiple positions, reordering arguments, or referencing earlier commands — press <C-f>. This opens the command-line window without abandoning your in-progress command, giving you full Normal, Insert, and Visual mode editing before execution.
How it works
- While typing a
:command (or/search), press<C-f> - Vim opens the command-line window with your current command visible at the bottom
- Use any Vim motion or operator to edit:
b,w,cw,dd,p, visual selection, etc. - Press
<CR>on any line to execute that command - Press
<C-c>or:qto close and return to Normal mode without executing
This is distinct from q: (which opens the command-line window from Normal mode) — <C-f> works when you're already in the middle of typing and don't want to lose your work.
Example
You type :s/\(\w\+\)_\(\w\+\)/ and realize you need to fix the regex. Instead of <Esc> and retyping, press <C-f>. The window opens with your pattern visible, you use F_ to jump to the underscore, make edits with Normal mode commands, then press <CR> to execute.
Tips
- Command history is visible above — navigate with
j/kto reuse and modify past commands q/andq?open analogous windows for search history from Normal mode- Works the same way when entering a
/search: press<C-f>while typing a pattern - See
:help cmdwinfor all available mappings inside the command-line window