3

I would like to insert some Python-generated text at the current cursor position in insert mode using the Vim Python interface. The closest I have so far is:

imap <c-x><c-r> <c-o>:python vim.current.line += "trivial example"

This will append "trivial example" rather than put it at the current position. How can I insert the text at the cursor instead?

0

2 Answers 2

3

It is generally easier to use pyeval (py3eval, pyxeval) and the expression register:

imap <c-x><c-r> <c-r>=pyxeval('python expression')<cr>
0

if you want to use : py, you probably should use vim.command

function dosomething()
     :py import vim 
     :py vim.command("let tt ='text' ")
     return tt
endfunction

and call it by <C-R>=dosomething()

or

 function dosomething()
     :py import vim 
     :py vim.command("norm i"+ 'TEXT' )
endfunction

and call it by <esc>:call dosomething()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.