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

# 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


Bash history and bang commands