Skip to content

Execute command line commands from inside vim

Igor Irianto on December 07, 2019

One vim command I have been experimenting with recently is bang (!) command to execute external commands from within vim (:h :!). Why is this so a... [Read Full]
markdown guide

Should note that :term is also a very useful command! You can move around in the terminal buffer like you'd expect in vim which makes it really convenient to have a full terminal that can easily move text between files and the shell.


You're right! The terminal command :)
I like how we can still switch to normal mode while in :term, giving us more power!


Do not have time to read, but I like it first, read later. Your post is always good.


Haha, thank you Sang! I am always happy knowing that my post affects other readers 👍
I noticed you've reacted most of my vim posts too! 😁


I followed you so I will never miss any post then.
Btw, this post is awesome. I use fzf and with this bang I can completely get rid of heavy Nerdtree :D
Today, I stuck with how can I create new folder and I remember your post, so, with :!mkdir .... I can make things happen!

Thank you!

Haha thanks! I am genuinely flattered :) I always love a good feedback from someone like you too!

Anyway, it just got me thinking what if we can use quickfix window to complement some command lines like !ls so we are less dependent on NERDTree... sorry for muttering, not really sure exactly what I'm trying to do either haha. Maybe I'll write another post someday if I think of this clearly!


With :.! you can insert the result of the command into the current buffer (the file you are currently editing).


I just tried it - this is awesome! Does :.!{cmd} work exactly the same as :r !{cmd} then? If not, what's the difference?


Actually I didn't know about :r !{cmd}, so I'm not sure. From a quick test I noticed that :r inserts a newline above the content, while :.! does not. Other than that, dunno ¯\(ツ)/¯.

Oh, that's an interesting behavior :) Even a newline makes a difference 😎

:r !grep word file
:r !sqlite3 data.sqlite "select value from Snippet where key='word'"
:!php %

Oh nice! I didn't think about sqlite and grep. Those two would be super handy.
Regarding sort, I am already used to vim's built-in sort in vim (:h sort) though :)

code of conduct - report abuse