Send text to a shell tool
:%write !wc -l
Example
Normal mode. Lines: alpha, beta. Shell tool wc is installed.
alpha
beta- :%write !wc -l<CR> wc reports 2 lines · buffer unchanged
Details & Vim help
Send a range to a command’s standard input without replacing the buffer.
Measure or inspect text using an external tool.
The ! command runs a shell program; it is different from :write! file. This example assumes wc is installed. It does not save the buffer to its current file or clear the modified flag.
Buffer text stays unchanged; wc reports 2 lines in command output.
Try it in Vim
- Run :%write !wc -l<CR> to count all buffer lines.
- Read the command output.
- Return to editing when Vim prompts.