vim Using Python for Vim scripting Executing multi-line Python code


Every Python statement in Vim should be prefixed with the :python command, to instruct Vim that the next command is not Vimscript but Python.

To avoid typing this command on each line, when executing multi-line Python code, it is possible to instruct Vim to interpret the code between two marker expressions as Python.

To achieve this, use:

:python << {marker_name}
a = "Hello World"

where {marker_name} is the word you want to use to designate the end of the python block.


:python << endpython
surname = "Doe"
forename = "Jane"
print("Hello, %s %s" % (forename, surname))

would print:

Hello, Jane Doe