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

How do I open the command-line window while typing a command on the : prompt?

Answer

<C-f> (from command-line mode)

Explanation

When you are partway through typing a long or complex Ex command on the : prompt, you can press <C-f> to open the command-line window. This gives you a full Vim editing buffer containing your command history, with your current in-progress command at the bottom. You can edit it with all of Vim's normal mode power — motions, text objects, registers — then press <CR> to execute.

How it works

  • <C-f> — while on the : (or / or ?) command line, switches from the single-line prompt to the command-line window
  • The window shows your command history, one command per line, with the current command at the bottom
  • Edit using all normal Vim commands — w, b, ci", paste from registers, etc.
  • Press <CR> on any line to execute that command
  • Press <C-c> or :q to close the window without executing

Example

You start typing a complex substitute command:

:%s/\v(foo|bar)_(\w+)/\2_\1/g

Midway through, you realize you need to fix part of the regex. Instead of using arrow keys to navigate the command line character by character, press <C-f>. The full command appears in an editable buffer where you can use f/, ci(, or any Vim motion to quickly edit the pattern.

Tips

  • This is different from q:q: opens the window from normal mode, while <C-f> opens it from an active command line, preserving what you've already typed
  • Works on search prompts too: press <C-f> while typing a / or ? search to edit it in a buffer
  • You can configure which key opens the window with :set cedit

Next

How do I return to normal mode from absolutely any mode in Vim?