Tuesday, December 4, 2012

Re: how to execute ranger from gvim

On 12/04/2012 01:19 AM, Gary Johnson wrote:
> On 2012-12-03, ping wrote:
>> On 12/3/2012 8:06 PM, Gary Johnson wrote:
>>> exe 'edit' readfile(tmpfile)[0]
>>>>> " edit the file whose name
>>>>> " is in the first line of
>>>>> " tmpfile. (readfile()
>>>>> " returns the contents of the
>>>>> " file as a list of lines.
>>>>> " List element 0 is the
>>>>> " first line.
>> thanks for the line by line annotation, now I understand!
>>
>> just one last small thing, in the above line, won't it suffice just:
>> exe readfile(tmpfile)
>> ?
> I'm not sure what you are expecting that command to do. The :exe
> command executes its argument string, so its argument string must be
> an executable Vim command. The readline() function returns a list
> (which is not a string), and the first element of that list will in
> this case be a file name. A file name is not an executable Vim
> command.
>
>> my test shows that will only give me a line of the file name, but now
>> the file contents so you are right,
>> but help says:
>> readfile({fname} [, {binary} [, {max}]])
>> Read file {fname} and return a List, each line of the file
>> as an item. Lines broken at NL characters. Macintosh files
>> separated with CR will result in a single long line
>> (unless a
>> NL appears somewhere).
>>
>> so readfile should have "read" the "file", why I only get the
>> filename instead?
> The readfile() function read the file whose name was the value of
> the tmpfile variable. That file contained the name of the file you
> selected in ranger.
>
> Maybe an example would be clearer.
>
> Let's say you execute :RangerChooser in an unnamed buffer. The
> tempname() function returns the name of a temporary file, something
> like /tmp/vuZJYgI/2, so ranger is executed with arguments like this:
>
> ranger --choosefile=/tmp/vuZJYgI/2 .
>
> You browse your home directory and select a file named hello.txt.
> Ranger saves the string "/home/ping/hello.txt" into the file
> /tmp/vuZJYgI/2 and exits. Vim now executes
> readfile("/tmp/vuZJYgI/2") which returns the list
>
> ['/home/ping/hello.txt']
>
> The zeroth element of that list, specified in the function as
>
> readfile(tmpfile)[0]
>
> is the string '/home/ping/hello.txt'. The command
>
> exe 'edit' readfile(tmpfile)[0]
>
> evaluates to
>
> edit '/home/ping/hello.txt'
>
> which is the desired result.
>
> Regards,
> Gary
that is super clear !(I also got it this morning on my way driving to
work :D )
good learning for me, thanks for all the explanations.

--
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

No comments:

Post a Comment