Execute a different command on the previous file

I often want edit a script with VI and then run it. There’s probably other ways to do this, but this is working for me:

# open file in VI
vi /usr/local/bin/my_script.php

# make some changes

# save the changes
esc :w!

# put VI in the background
^z

# use bash's previous command shortcut with :1 to represent the first argument of the previous command
php !!:1

# see results

# resume VI for more editing
fg

References

Bash history and bang commands

This is a personal website. Unless otherwise stated, the content and opinions expressed here are my own and not those of my employer.