Thanks for your answer. And Tony's way is working. pansz's method seems not working. But, I modify like following, it worked. map kkk :r<C-R>=Foo()<cr> I have checked in the Quick Refer. , <C-R>= work in Ex-command, and insert the result of Foo().
On 1月7日, 下午12时28分, Tony Mechelynck <[email protected]> wrote: > On 07/01/09 04:50, pansz wrote: > > > > > > > hengxing 写道: > >> Hi all! > > >> I wrote a function in my vim script like following: > > >> func Foo() > >> let g:fn= "/tmp/aa.txt" > >> return g:fn > >> endfunc > >> And at the same time, I wanted to create a 'map', > >> which can read the file content under cursor in vim, > >> which filename is the Foo return. > > >> I've written like the following but it doesn't work: > > >> map kkk :call Foo()|read<cr> > >> How can I pass the result of Foo to the "read" command? > > >> Ps: I don't want to read the file in the Foo function, because > >> I want the method which can pass the functions return to > >> the Ex-command. Or tell me it can't implement for some reasons. > > >> Thanks! > > > You can use something discussed in my previous thread:<C-R>= > > > nmap kkk :<C-R>=Foo()<cr><cr> > > > would do what you want. > > not nmap but cmap since you want the mapping to be active on the > command-line, after you type ":read ". Or else, if you always want to > use the same function to generate the operand of the ":read" command, > use ":execute" as follows: > > :map kkk :exe 'read' Foo()<CR> > > Best regards, > Tony. > -- > Finagle's Third Law: > In any collection of data, the figure most obviously correct, > beyond all need of checking, is the mistake > > Corollaries: > (1) Nobody whom you ask for help will see it. > (2) The first person who stops by, whose advice you really > don't want to hear, will see it immediately.- 隐藏被引用文字 - > > - 显示引用的文字 - --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
