wsdjeg / vim-fetch

Make Vim handle line and column numbers in file names with a minimum of fuss
http://www.vim.org/scripts/script.php?script_id=5089
MIT License
312 stars 17 forks source link

Make vim-fetch work as expected when using autochdir #39

Closed Alexis-D closed 1 month ago

Alexis-D commented 1 month ago

I used this plugin for years without any issues with version 2.0.2 (ce1bfad), I recently upgraded to bbb75c3172f766d1a62832df0ec7674c69a560ad where I noticed that vim-fetch stopped working as expected.

Here's a repro (importantly it needs set autochdir):

$ cat >a <<EOF
a
b
c
EOF
$ mkdir b
$ cp a b/
$ vim a:2 # works
$ vim b/a:2 # does not work, the opened buffer is `b/a:2` instead of the expected `b/a`
$

After git bisecting, I found that ef8a8e7 introduced the breaking change.

Digging some more it looks like the issue is around here:

https://github.com/wsdjeg/vim-fetch/blob/bbb75c3172f766d1a62832df0ec7674c69a560ad/autoload/fetch.vim#L143-L145

Given that autochdir is being used, the current working directory (getcwd()) is effectively set to b/ and from there b/a is not readable.

As a fix, we can use the :p modifier when calling expand which makes vim-fetch rely on absolute paths and therefore whether autochdir is used or not becomes irrelevant. I can't think of any downsides to this approach but I have little to no experience with VimL beyond maintaining my own .vimrc.

wsdjeg commented 1 month ago

Merged, thanks