My code is:
stuff = 'bla'
print(stuff)
I'm using the vim editor on linux mint to learn it.
So my question is:
I also have other code snippets above. But I want to for example try this two codes of lines out in the vim editor. Is there a way that i can execute that? Like in vscode where i can "Run Selection/Line in Python Terminal) with Shift + Enter.
Thanks for the help.
Vim also sports a
:terminalcommand. Looking at:help :terminalwill reveal the following information:This looks pretty complete: you can run a command (here: your Python interpreter) in a terminal, feeding it some lines from your buffer as input.
You would enter linewise Visual mode with ShiftV, select the lines to run and call
where
'<,'>stands for the current visual selection. Vim will already populate your command line with this when you type:in Visual mode.On hitting enter, Vim will open a terminal window which will show the output (if any) of the Python code you just ran. Type
:qto close the terminal and return to your normal editing.For convenience, consider writing a command or a mapping to quickly run Python code. The following line will define a
:Pythoncommand that runs the current visual selection or the whole buffer if nothing is selected: