One vim command I have been experimenting with recently is bang (
!) command to execute external commands from within vim (
Why is this so awesome? Let me show you some examples so you can do even more awesome things!
Yes, you read that right. If you have curl installed, you can curl from inside vim.
:r !curl -s 'https://jsonplaceholder.typicode.com/todos/1'
r[ead]. It is used to display the result. This command is so useful I mapped it as a shortcut (
nnoremap <Leader>cg :r !curl -s<Space>
Of course, this works with curl POST/PUT/DELETE.
I find this is useful when dealing with fake data and json files. You can do this with
:r !cat path/to/your.file
:r !ls **.*.js
If you want to check how many words in your current file, you can do
:!wc %. You can also do the same with
This is my personal favorite right after curl. This one is for tmux users. If you are working with multiple panes, you can send command to another pane.
:!tmux send-keys -t mySession:myWindow.2 "echo 'HELLO TMUX MAGIC'" Enter
Let me break it down:
tmux send-keyssends tmux instructions
mySession:myWindow.2is tmux's convention to target a specific pane. The syntax is:
"echo 'HELLO TMUX MAGIC'" Enteris the instruction
With this, I can send any instruction to any session, any window, any pane. I can tell my "Rails" session to execute
rspec on "Test" window's pane #2 while I am sitting inside a different session. How cool is that?
After running fairly lengthy command, you can quickly recall previous command with double bang:
I have only scratched the surface of
! potential; being able to execute external command unlocks many possibilities.
What command do you personally find it helpful to execute from inside vim?