2

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.

Van
  • 65
  • 9

2 Answers2

2
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

Sundeep
  • 23,246
  • 2
  • 28
  • 103
  • 1
    'cnoremap' can do the trick. But I find the link in the comments section the most useful in my case. Thanks anyway. – Van Aug 20 '16 at 07:49
0

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>
jarederaj
  • 1,350
  • 13
  • 18