Saturday, June 14, 2014

Re: use python script in vim

于 2014年06月14日 07:18, BaRud 写道:
> On Saturday, June 14, 2014 5:51:05 AM UTC+1, LCD 47 wrote:
>> On 13 June 2014, BaRud <bnrj.rudra@live.com> wrote:
>>
>>> Hi,
>>> I am trying to write a vimscript that uses python, but cant interface
>>> it properly.
>>> A minimal example is:
>>> function! Usrnm(nm)
>>> python << endpython
>>> import vim
>>> import os
>>> nm=vim.eval(os.getlogin())
>>> endpython
>>> echo nm
>>> endfunction
>>> call IMAP ('`foo', "@nm \<CR> Usrnm(nm)", "fortran")
>>> Can anyone please help me achiving this? i.e. getting the login name
>>> to be used in the IMAP call?
>>
>>
>> You got it backwards, vim.eval() is for passing Vim values to
>>
>> Python, not the other way around. You probably want vim.command()
>>
>> instead:
>>
>>
>>
>>
>>
>> function! Usrnm()
>>
>> if has('python')
>>
>> python <<EOT
>>
>> import vim
>>
>> import getpass
>>
>> vim.command("let nm = '%s'" % getpass.getuser())
>>
>> EOT
>>
>> echo nm
>>
>> else
>>
>> echo 'no python, no cry'
>>
>> endif
>>
>> endfunction
>>
>>
>>
>>
>>
>> For returning dictionaries, lists, or funcrefs, there is also
>>
>> vim.bindeval(), thanks to ZyX. :) See the manual for details.
>>
>>
>>
>> /lcd
> Thanks, but how can I call that value in the IMAP call? please.
>
try this:
========================code =========================================
py import os

call IMAP ('`foo', "@nm \<CR> " . pyeval("os.environ['USER']") , "fortran")
========================code =========================================


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment