brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: q: in Vim opens your command history as a window you can edit

Vim
~/tips/tip-vim-command-line-window-q-colon

(move to the line with k, edit it)

Opens your Vim command history as a buffer, so you can edit an old command and rerun it.

I retype long Ex commands far too often, usually because one character in a substitute was wrong. Vim has a cleaner way: in Normal mode, q: opens your command history as a normal buffer that you can move around in and edit.

Type q: and a window opens at the bottom, filled with the command-line history. The last line is the command you are typing right now. Because it behaves like any other text, you can press k to climb up to the old command, fix it with the usual motions, and run it.

q:
(move to the line with k, edit it)
<Enter>

Pressing Enter runs the line under the cursor, in Normal or Insert mode. Two close relatives exist for search history: q/ for forward searches and q? for backward ones. If you are already halfway through typing a command, CTRL-F on the command line switches to the same window, and your half-typed text is on the last line.

To leave without running anything, use :quit. CTRL-C goes back to the command line with the current line as the command, so you can still adjust it before sending.

There are limits. Edits to any line other than the one you run are thrown away when the window closes, so do not treat it as a scratch file. You cannot jump to another window or buffer from inside it, you cannot open a second command-line window within it, and it does not open while you are recording a macro, because the q ends the recording. The Vim help also notes you cannot use it to enter an encryption key.

The help text says you can write the buffer to a file, which is a handy way to keep a copy of your history. For me it mainly means I stop retyping long commands.

Further reading: Vim help: cmdline.txt, the command-line window

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Vim tips :%s/<Ctrl-r><Ctrl-w>/newname/g /oldname find . -name "*.conf" | vim – vim --clean file.txt :set textwidth=72 All Vim tips (45) All topics

Link