Today I Learned

A Hashrocket project

Use !! to quickly insert result of a bash command

Vim has the ability to read a result of a bash command into the current buffer. This can be done in many ways:

:read !echo "hello world"

To replace the content of the whole file with the result of a command use %!:

:%!cat file_to_copy_from.c

Similarly to replace the current line use . instead of %:


The command above will insert an ascii calendar into your buffer.

Last night I was testing to see what each of the keys in the number row do when used with the Shift key in Vim. One of the most interesting NORMAL mode mappings I found was the bangbang (!!). If pressed it opens the command line with .! and places your cursor right after that.

This allows for quickly bringing in data such as the date when you are working on a blog post.


Please tweet at me @dorian_escplan and @hashrockettil if you find other interesting uses for it.

Every developer at Hashrocket is a Vim expert. Check out our development environment, Dotmatrix, and if you are in Chicago, come to the monthly Vim Chicago Meetup hosted at our Chicago office.