Insert the path of the Python interpreter easily
How many times have you written “
#!/usr/bin/env python” in your life? A few hundred times? :) How to insert this line easily?
I mainly use vim. So far I have done it the following way.
In vim, type this on the first line in normal mode. This is the mode that vim will usually start in, which you can usually get back to with ESC. At the end press ENTER.
!!” brings you to command mode and the current line (which was empty) is replaced with the output of “
which env“. Thus the first line becomes “
/usr/bin/env“. All you need to do is add “
#!” and “
Fine, but I got fed up with this. It’s still too much typing. How to do it easier?
Write a bash script called “py” with the following content:
echo "#!`which env` python"
Put it somewhere in your
PATH and make it executable.
Then, in vim type this on the first line:
Phew. I should have thought of it years ago.