I found this vim tip which allows you to evaluate a Python expression and displays the result in the command line. You just have to add
:command! -nargs=+ Calc :py print <args>
:py from math import *
to your .vimrc
and then you can do e.g.
:Calc sum([x^2 for x in range(100)])
Which displays 4950
in my command line, as if I had executed :echo 4950
.
This is convenient, but I would like to know how I can either append the result at the location of my cursor, or add it to a certain register.
py vim.current.buffer.append(str(sum([x^2 for x in range(100)])), vim.current.window.cursor[0])
Traceback (most recent call last): File "<string>", line 1 in <module> NameError: name 'vim' is not defined
+python
or+puthon3
internal Python interpreteur have modulevim
,:he python-vim
for more exploration.