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.

3
  • 1
    You ca n use aliases, read: stackoverflow.com/a/4642855/1005215 Commented Aug 20, 2016 at 6:09
  • How about just symlink /usr/local/bin/py to /usr/bin/python3 ;) Commented Aug 20, 2016 at 6:15
  • 2
    Also this is really not a Python question Commented Aug 20, 2016 at 6:24

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

'cnoremap' can do the trick. But I find the link in the comments section the most useful in my case. Thanks anyway.
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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.