1

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much Ingo
The at the top "0" number reverse the list but it works very fine also without it. It would be nice to use the "0" only for the 1st item. :)
If you start with an empty buffer, the 0 indeed is optional. Thanks for accepting my answer!
1

If you have this Redir, you can recover already printed text with:

:Redir messages

Example:

:py3 print('print to stdout')
:Redir messages
/print to stdout

It will be at the end of the buffer that opens.

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.