How do I make Vim display partial key sequences and selected character counts in real time?
Answer
:set showcmd
Explanation
The showcmd option makes Vim display the currently-typed command in the bottom-right corner of the screen, giving you live feedback as you build up key sequences. It also shows the dimensions of visual selections. For users who work with counts, operators, and complex motions, showcmd provides a constant heads-up display of what Vim is about to do.
How it works
With showcmd enabled, the bottom-right corner shows:
- Pending operator + count: If you type
3d, you see3dbefore the motion, so you know Vim is waiting for a motion to delete 3 of something - Visual selection size: In character visual mode (
v), it shows the number of characters selected. In line visual mode (V), it shows the line count. In block visual mode (<C-v>), it shows{rows}x{cols}— the dimensions of the block - Partial keystrokes: If you press
<C-w>while waiting for a window command, it shows that prefix so you know the key was registered
Example
Enable it permanently in your vimrc:
set showcmd
Then in normal mode, press 5, and the status area shows 5. Press d, it shows 5d. Press w, and Vim deletes 5 words — then the display clears.
In visual block mode, select a 3×10 region and the display reads 3x10.
Tips
showcmdis on by default in many distributions via the built-indefaults.vim, but it is not on by default in a bare Vim installation- It has no performance cost — the display update is negligible
- Combine with
showmode(which shows-- INSERT --,-- VISUAL --, etc.) for full situational awareness - Particularly useful when learning Vim: seeing
dwaiting for a motion reinforces the operator + motion grammar