[vim/vim] Incorrect filetype when opening a file from netrw listing on remote system (Issue #14400)

24 views
Skip to first unread message

Balki

unread,
Apr 3, 2024, 1:02:27 PM4/3/24
to vim/vim, Subscribed

Steps to reproduce

  1. Open vim with below command

    vim --clean --cmd "set loadplugins" scp://remotehost//etc/
    
  2. Select fstab file and press enter

  3. Run :set ft?

Expected behaviour

See filetype=fstab
But shows filetype=netrw

Opening in local works correctly. i.e. vim --clean --cmd "set loadplugins" /etc/
Also woks correctly when directly opening the remote file. i.e. vim --clean --cmd "set loadplugins" scp://remote-host//etc/fstab

Version of Vim

vim 9.1 with pathces upto 1-252

Environment

Archlinux

Logs and stack traces

:scriptnames
  1: /usr/share/vim/vim91/defaults.vim
  2: /usr/share/vim/vim91/filetype.vim
  3: /usr/share/vim/vimfiles/ftdetect/PKGBUILD.vim
  4: /usr/share/vim/vimfiles/ftdetect/SRCINFO.vim
  5: /usr/share/vim/vimfiles/ftdetect/meson.vim
  6: /usr/share/vim/vim91/ftplugin.vim
  7: /usr/share/vim/vim91/indent.vim
  8: /usr/share/vim/vim91/syntax/syntax.vim
  9: /usr/share/vim/vim91/syntax/synload.vim
 10: /usr/share/vim/vim91/syntax/syncolor.vim
 11: /usr/share/vim/vim91/colors/lists/default.vim
 12: /usr/share/vim/vimfiles/plugin/black.vim
 13: /usr/share/vim/vimfiles/plugin/fzf.vim
 14: /usr/share/vim/vim91/plugin/getscriptPlugin.vim
 15: /usr/share/vim/vim91/plugin/gzip.vim
 16: /usr/share/vim/vim91/plugin/logiPat.vim
 17: /usr/share/vim/vim91/plugin/manpager.vim
 18: /usr/share/vim/vim91/plugin/matchparen.vim
 19: /usr/share/vim/vim91/plugin/netrwPlugin.vim
 20: /usr/share/vim/vim91/plugin/rrhelper.vim
 21: /usr/share/vim/vim91/plugin/spellfile.vim
 22: /usr/share/vim/vim91/plugin/tarPlugin.vim
 23: /usr/share/vim/vim91/plugin/tohtml.vim
 24: /usr/share/vim/vim91/plugin/vimballPlugin.vim
 25: /usr/share/vim/vim91/plugin/zipPlugin.vim
 26: /usr/share/vim/vim91/autoload/netrw.vim
 27: /usr/share/vim/vim91/syntax/netrw.vim
Press ENTER or type command to continue


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14400@github.com>

Christian Brabandt

unread,
Apr 3, 2024, 3:17:25 PM4/3/24
to vim/vim, Subscribed

Hm, this comes from this commit: 71badf9#diff-39baf27d8f62071617bbef12f874cce31c0ebd02ec99e7b119474ca870c636a3

The problem is, that filereadable() returns 0 for remotely accessed files. I think the following patch fixes it, explicitly checking against remote protocols:

diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim
index b91dab4e7..b9d8178a6 100644
--- a/runtime/autoload/netrw.vim
+++ b/runtime/autoload/netrw.vim
@@ -1803,7 +1803,7 @@ fun! s:NetrwOptionsRestore(vt)
 "  call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
   if !exists("{a:vt}netrw_optionsave")
 "   call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
-   if filereadable(expand("%"))
+   if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
 "    call Decho("..doing filetype detect anyway")
     filetype detect
 "    call Decho("..settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14400/2035398739@github.com>

Balki

unread,
Apr 3, 2024, 3:42:56 PM4/3/24
to vim/vim, Subscribed

Can confirm patch works good. Thank you for quick fix!


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14400/2035438929@github.com>

Christian Brabandt

unread,
Apr 3, 2024, 4:49:28 PM4/3/24
to vim/vim, Subscribed

Closed #14400 as completed via 08d2401.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/14400/issue_event/12348201373@github.com>

Reply all
Reply to author
Forward
0 new messages