On Tue, Sep 29, 2009 at 2:55 PM, Reckoner <recko...@gmail.com> wrote: > > Is it possible to do something like: > > :g/\(\w+\) .*/python foo(\1) > > and then have all the matching lines changed to the output of the > python foo() function? > > For example, > > +-------------------------------- > we are on line one > we are on line two > +-------------------------------- > > and given > > def foo(x): return len(x) > > we get > > 2 are on line one > 2 are on line two > > since the matching part ("we") has two letters. > > I hope that made some sense. > > The main thing is to somehow pull out the matching part in the \(\w+\) > and feed it into some other Python function. >
You can't call python code in an expression, so you have to "push" the result in as a Vim variable and use the variable. Try something like this (untested): :g/\(\w+\) .*/CallFoo(submatch(1)) func! CallFoo(arg) let g:foo_arg = a:arg python foo() return g:foo_result endfun def foo(x): vim.command('let g:foo_result = '+str(len(vim.eval('g:foo_arg'))) A pyeval() function will be nice. -- HTH, Hari > > Thanks in advance. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---