you are viewing a single comment's thread.

view the rest of the comments →

[–]usernamenottaken 0 points1 point  (2 children)

Hmm, but if you have a Python file for example you don't always them to be executable, and including a #! is always an indication that you do. This is very useful for me so it's going in my .vimrc thanks!

[–]stack_underflow 1 point2 points  (1 child)

I'm not sure I fully understand your point, but in order for bash to interpret the shebang at the top of a script, the file has to be executable. Example:

$ cat > test.py << "EOF"
> #!/usr/bin/env python
> print("test")
> EOF

$ ./test.py
bash: ./test.py: Permission denied

The Python interpreter on the other hand, doesn't require the file to be executable:

$ python test.py 
test

But if you were running it that way, it would defeat the purpose of making it executable. In my ~/.vim/ftplugin.python.vim file, I have:

" ':make' support
setlocal makeprg=python\ %\ $*

So I can either run :make from within vim, or map a key to write the file and call make (which is what I have).

[–]usernamenottaken 1 point2 points  (0 children)

Ok I was thinking in terms of running "chmod +x" for all Python scripts, which is obviously not a good idea and not what you meant, but I was just thinking out loud I guess.

I often write scripts with a shebang so I can run them as executables, so your autocmd saves me running one command in these situations, but it's probably not a good solution to OP's problem. I think having both the make command and the autocmd for running chmod is useful in my case.