Loading ...
Sorry, an error occurred while loading the content.

134851Re: how to execute ranger from gvim

Expand Messages
  • Gary Johnson
    Dec 3, 2012
    • 0 Attachment
      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

      > 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


      The zeroth element of that list, specified in the function as


      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.


      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
    • Show all 16 messages in this topic