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 %
:
:.!cal
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.
:.!date
Please tweet at me @dorian_escplan and @hashrockettil if you find other interesting uses for it.
Tweet