To run a script using python3+ in vim (having Python2.7 as default), you need to type:
:!python3 <filename.py>
Technically, how do you run it with Python3+ with just:
:!python <filename.py>
An alias perhaps, just to shorten it.
To run a script using python3+ in vim (having Python2.7 as default), you need to type:
:!python3 <filename.py>
Technically, how do you run it with Python3+ with just:
:!python <filename.py>
An alias perhaps, just to shorten it.
cnoremap !py !python3<Space>
This would substitute !py
with !python3
anywhere on the command line.
It is perhaps better than using cnoremap py python3<Space>
as !py
would not be as common as possibility of py
on the command line
Also, you might notice vim
waiting a few moments whenever you type !
on the command line. You can continue typing regardless
If you're writing a lot of python consider using map instead of remapping names of applications in vim only. Using map will probably save you a few key strokes and it will make what's happening more explicit. ctrl+shift+p seems like a good option. Of course, you'll change that to whatever works better in your own flow.
" ctrl+shift+p to execute script with python3
map <C-S-p> :!python3<Space>