Reman February 2016

How to print the output of python code in Vim buffer?

Example (in vim function):

python3 << endpython
import vim,sys,locale
locale.setlocale(locale.LC_ALL, vim.eval("Locale"))
for i in range(1,10,2):
    print(locale.format('%.2f', i))
endpython

The print command, prints the numbers as an echo message.
I would like to print the numbers at the top of the current buffer.
How can I do this?

Answers


Ingo Karkat February 2016

You can access the current buffer and append after line 0 (= inserting at the top) via:

vim.current.buffer.append("example text", 0)

See :help python-buffer.

Post Status

Asked in February 2016
Viewed 3,176 times
Voted 14
Answered 1 times

Search




Leave an answer