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

How do I edit a complex Ex command in a full editing window?

Answer

q: or <C-f> from : prompt

Explanation

The command-line window (q:) opens a full Vim buffer containing your Ex command history. You can navigate, search, edit, and re-execute any previous command using all of Vim's editing power.

How to open it

q:      " Open command-line window (from normal mode)
q/      " Open search history window
q?      " Open backward search history window
<C-f>   " Open command-line window while already typing a : command

How to use it

  1. q: opens the command history as a buffer
  2. Navigate with j, k, /search, etc.
  3. Edit any line using normal Vim commands
  4. Press <CR> on a line to execute it
  5. Press <C-c> or :q to close without executing

Example workflow

  1. You ran a complex substitute earlier: :%s/\v(\w+)\.(\w+)/\2::\1/g
  2. You need to run it again with a small modification
  3. Press q: to open command history
  4. Press /subst<CR> to find it
  5. Edit the command (e.g., change g to gc)
  6. Press <CR> to execute the modified command

Tips

  • The command-line window supports all normal mode editing, search, and yank/paste
  • <C-f> while typing a : command is extremely useful — start typing, then realize you need to edit, press <C-f>
  • The window shows your most recent commands at the bottom
  • You can yank from command history to paste into a script or vimrc
  • q/ is equally useful for editing complex search patterns
  • Set cmdwinheight to control the window height: :set cmdwinheight=15
  • Documented under :help command-line-window

Next

How do I run the same command across all windows, buffers, or tabs?