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. 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.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.