134846Re: how to execute ranger from gvim
- Dec 3, 2012On 2012-12-03, ping wrote:
>Setting dir that way doesn't make sense to me. Either I wasn't
> On 12/03/2012 01:44 PM, Gary Johnson wrote:
> > " RangerChooser()
> > "
> > " Ranger version 1.4.2 or later is required to run this function. That's when
> > " the --choosefile option was added.
> > fun! RangerChooser(...)
> > let tmpfile = tempname() " Get the name of a temporary
> > " file.
> > if a:0 > 0 && a:1 != "" " If the user has supplied an
> > " argument,
> > let dir = a:1 " set dir to that argument,
> > elseif expand("%") " otherwise if the current
> > " buffer has a name,
> > let dir = "." " set dir to the current
> > " working directory.
> > else " Otherwise,
> > let dir = expand("%:p:h") " set dir to the directory
> > " containing the current
> > " buffer.
thinking straight when I wrote it or I'm not thinking straight now.
> > endifI annotated the function above.
> > exe 'silent !ranger --choosefile='.tmpfile dir
> > " Execute ranger in the
> > " directory given by dir and
> > " put the selected file in
> > " tmpfile.
> > if filereadable(tmpfile) " If tmpfile is readable,
> > exe 'edit' readfile(tmpfile)
> > " 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.
> > call delete(tmpfile) " Delete the temporary file.
> > endif
> > redraw! " The display may have been
> > " messed up by ranger, so
> > " redraw it.
> > endfun
> > "map ,r :call RangerChooser()<CR>
> > command -nargs=? RangerChooser call RangerChooser("<args>")
> that are really magic codes and great vim+ranger combination. It works, I don't
> quite understand exactly how it works though...
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
- << Previous post in topic Next post in topic >>