vifm / vifm.vim

Vim plugin that allows use of vifm as a file picker
335 stars 19 forks source link

Follow links when handling files #28

Closed rbong closed 4 years ago

rbong commented 5 years ago

Vim uses resolved filenames, and so we must use the resolved file path when using commands like :buffer.

Gets an error when following links in some cases without this change.

xaizek commented 5 years ago

Vim uses resolved filenames

In what cases? I get these results in my tests:

[~]$ ls -l .bashrc .inputrc
lrwxrwxrwx 1 xaizek users 13 2013-06-01 22:12 .bashrc -> .files/bashrc
lrwxrwxrwx 1 xaizek users 14 2013-06-01 22:11 .inputrc -> .files/inputrc
[~]$ vim +'cd /' -p .bashrc .inputrc 

:ls
  1 %a   "~/.bashrc"                    line 1017
  2  a   "~/.inputrc"                   line 0
call map(flist, 'resolve(fnameescape(v:val))')

This attempts to resolve an escaped path. The functions should be called in the opposite order.

rbong commented 5 years ago

In what cases?

It happens when editing files in symbolically linked directories. My mistake for not thinking of plain files.

The functions should be called in the opposite order.

You are right. And I believe that resolve only needs to be called on the first file, since it's the only file that :buffer is called on.

We will want something more like this:

let firstfile = resolve(fnamemodify(unescaped_firstfile, ':h'))
        \ .'/'.fnamemodify(unescaped_firstfile, ':t')
execute 'buffer' fnameescape(fnamemodify(firstfile, ':.'))

I am doing more testing now.

rbong commented 4 years ago

I updated and tested with both linked files and directories with special characters in their names. In my tests I was able to call resolve() after fnameescape() without problems.

xaizek commented 4 years ago

On 8.1.2291 I get E94: No matching buffer for ... because resolve('link\ with\ spaces/file') just returns link\ with\ spaces/file for me.

rbong commented 4 years ago

@xaizek thanks, I knew there must have been a case that must have resulted in error but I didn't want to introduce more complexity without knowing for sure. I've moved things around now so that the unescaped filename is used. It unfortunately required touching more of the callback function, but now I've tested with:

xaizek commented 4 years ago

Thanks!