Reuse parts of previous command
So, you're in bash and you've just run a command on some file, like you've ls -led it.
ls -l some/long/filename.here
...and now you want to open that file in, say, vim. You could arrow up, delete the ls -l and replace it with vim - or...
vim !!:$
Tada, the !!:<position> allows you to extract the zero-based bash arguments from the previous command in your history. The $ represents the last argument, but you can use !!:0 or any other number to get at the args. You can even do: !!:1-$ to get from index 1 to the end.
Written by Jason King
Related protips
2 Responses
In fact, vim !$ is enough in your example.
over 1 year ago
·
Awesome, I didn't know about that. I also recently discovered that there's even a var that gets set: $_ is set to the last arg of the previous command.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Related Tags
#bash
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#