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

How do I open the command-line window while in the middle of typing a command?

Answer

<C-f>

Explanation

While typing in Vim's command line (after pressing :), pressing <C-f> opens the command-line window with your current, unfinished command already filled in. This gives you a full Vim buffer where you can use any motion, edit your command precisely, browse through command history, and then execute it with <CR>. It is the most natural way to compose a long or complex Ex command — start typing it, then switch to the command-line window for full editing power.

How it works

  • Type : then begin entering a command
  • Press <C-f> at any point to transfer the current input into the command-line window
  • The command-line window opens with your partial command on the last line, cursor positioned there
  • Edit using normal Vim motions (search, change, yank, etc.)
  • Press <CR> on the line you want to execute; press <Esc> or :q<CR> to cancel
  • Pressing q: from normal mode opens the same window positioned at the last command (without carrying over any in-progress text)

Example

You start typing a long substitution:

:s/foo\(bar\|baz\)/

Then realize you want to carefully finish the replacement. Press <C-f> — the window opens with that pattern, and you can edit it with full Vim motions before pressing <CR> to execute.

Tips

  • Use <C-f> in search mode too (/ or ?) — it opens the search history window the same way
  • Inside the command-line window, <C-c> or <Esc> closes it without executing
  • Historical commands appear above; navigate with j/k or search with / to find and re-run a previous command

Next

How do I reformat a paragraph or motion to fit within the text width without moving my cursor?