Your intuition is correct: the two autocommands are very similar.
The second autocommand runs when you read or start editing a new file with a name that ends in the
.py extension. The first runs when the file type is set to Python, which Vim will generally do automatically for
However, try running the following commands with each of the two autocommands in place:
You will find that the
Filetype autocommand runs, but the other does not. For this reason, you should probably use the first version if you want to use an autocommand for this.
However, in my opinion, there is an even better solution. Create a file in the location:
And enter the contents:
If you don't already have filetype plugins enabled, you will need to do so by adding
plugin to the
filetype command in your vimrc file:
filetype plugin on
This will have the same effect, no autocommands required!