1

To run current Python script/file in Vim I use this command:

:!python %

The problem is that this locks Vim so I can't look at or edit files in Vim until I close the cmd window.

This is for Windows.

How can I run the Python-script without locking the current script/file in Vim?

6 Answers 6

2

On Unix, you would append & to the command (a shell feature); Windows Vim has the special :!start command for that.

:!start python %
Sign up to request clarification or add additional context in comments.

Comments

1

try this, if your script don't have output, or stream output to file

:!python % &

pressing enter should return you to vim

2 Comments

Still the same problem and also the & character causes and error message.
It seems like on windows it not work, according this link superuser.com/questions/198525/… :!START \B python % should work
1

Vim has problems running things asynchronously, there's a few ways around this, but the easiest for you would be to grab a plugin that can do it for you.

Try tpope's Dispatch: https://github.com/tpope/vim-dispatch

Then you can run :Start! python % to run it in the background.

Comments

0

Or simply execute pyf % or map it to some key, for instance map <F8> pyf %<CR>

Comments

0

Since version 8.0, if your Vim was compiled with +terminal feature, you can see the output of your script in a separate window while editing other files.

:ter python %

or

:%ter python

enter image description here

Comments

0

I am usually using vim in a tmux window, split horizontally in two, for this and use the following mapping, assuming that I want to run the python script in the lower pane (pane number 1),

nnoremap ,s :execute '!tmux send-keys -t 1 ''python ' . expand('%:p') .' '' Enter '<cr>

If you now press ,s, this will execute your script in pane 1

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.