Tuesday, February 10, 2009

User Input From Vim to Python script

hi, ever wondering how to prompt a user for some input from python script within vim, but first make sure you have imported the vim module

def python_input(message = 'input'):
vim.command("call inputsave()")
vim.command("let user_input = input('" + message + " : ')")
vim.command("call inputrestore()")
return vim.eval('user_input')

now everytime you wanna prompt user, in your python script do something like

input = python_input('input something')

it will prompt the user to input something with 'input something' as the caption of the prompt, in the command-line

for more detail

:help input()

hope, this would help.

No comments: