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
q:opens the command history as a buffer- Navigate with
j,k,/search, etc. - Edit any line using normal Vim commands
- Press
<CR>on a line to execute it - Press
<C-c>or:qto close without executing
Example workflow
- You ran a complex substitute earlier:
:%s/\v(\w+)\.(\w+)/\2::\1/g - You need to run it again with a small modification
- Press
q:to open command history - Press
/subst<CR>to find it - Edit the command (e.g., change
gtogc) - 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
cmdwinheightto control the window height::set cmdwinheight=15 - Documented under
:help command-line-window