macro

:!

:! runs a shell command and shows its output; with a range, :[range]!cmd pipes those lines through cmd and REPLACES them with its output. The bridge from Vim to the rest of your Unix toolbox.

:!{cmd}   :[range]!{cmd}  (command mode)

Variations

Keystroke Effect
:!! Re-run the last :! command
:r !{cmd} Read shell output INTO the buffer at cursor
:%!sort Sort the whole buffer through sort(1)
:.!date Replace current line with `date` output

Examples

:!ls -la

Run ls without leaving Vim

:%!jq .

Format the whole buffer as JSON via jq

:r !curl -s https://api.example.com

Read remote HTTP response into the buffer

Gotcha

% expands to the current filename in :! — a naked % in :!rm % deletes the file you're editing. Escape it (\%) if you need a literal percent sign.

Related

← All Vim commands · Vim cheat sheet