The command line in Vim for ex commands can be edited with a few of the GNU Readline key combinations that may be familiar to Bash or Emacs users, so it’s reasonably easy to edit it, for example to type in complex search patterns and replacements.
However, if you want the full facility of Vim editing for your commands, it can be helpful to use Vim’s command line window, which will allow you to enter commands and edit previous ones with the usual normal and insert mode.
You can open the command line window from normal mode in one of four ways:
q:
— Open with a command history from normal modeq/
— Open with a search history from normal mode (to search forward)q?
— Open with a search history from normal mode (to search backward)Ctrl+F
— Open with a command history from command mode
Note that this doesn’t work while you’re recording macros, since pressing q stops the recording.
The window is always immediately above the status bar, and its height can be
set via the cmdwinheight
option.
Command line window
Once the command line window is opened with q:
, you can browse through it and
press Enter on any line to issue the same command again. You can also edit it
beforehand, perhaps to fix a mistyped command. The window will close when this
is done, but you can close it with Ctrl+W, C
the same as any other window if
you change your mind.
Note that you can’t move to another window while this one is open, nor can you load another buffer into it.
Search window
Similar to the above, if you open the command window with q/
or q?
, it
shows a history of your searches, and pressing enter on any line will issue the
same again, in the appropriate direction.
For more information on how the command window works, check out :help
command-line-window
.