2

I would like to create an individual vim command that does the following:

  1. save the current file
  2. run the current file with python

Currently I have to do it like this:

:w

:! python3 {filename}

Instead, I would like to do this:

:pyRun

or something similar

1
  • 2
    :set autowrite and you can just do :!python3 % without having to :w first.
    – melpomene
    Commented Mar 17, 2019 at 15:09

1 Answer 1

1

You can chain commands with |. So

:w | ! python3 %

will save the buffer and run it with python3.

See :help :bar and :help c_% for more information.

You can create a command for this like:

:command PyRun execute 'w <bar> ! python3 %'

Note that custom commands in vim have to start with an uppercase letter.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.