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

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 :q to 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 instead
  • q: opens the command-line window from Normal mode (history only, no in-progress command)
  • :q or <C-c> closes the command-line window without executing

Next

How do I quickly configure Vim to parse compiler errors for a specific language using a built-in compiler plugin?