How to run a "section" of a python script, like Matlab

Viewed 237

When using vim (or any other text editor) for python scripts, is there a way to run a section of your script alone?

Matlab has a feature where beginning a line with %% splits the lines of code that follow into a section of its own, that can be run independently. Is there a way of achieving this without having to use iPython? Even if the solution is a bit hacky, it would be an improvement over what I currently am doing, which is commenting out blocks that I don't want to run.

1 Answers

A generic solution would be vim-slime: https://github.com/jpalardy/vim-slime

SLIME is an Emacs plugin to turn Emacs into a Lisp IDE. You can type text in a file, send it to a live REPL, and avoid having to reload all your code every time you make a change.

Vim-slime is a humble attempt at getting some of these features into Vim. It works with any REPL and isn't tied to Lisp.

Related