[vim/vim] netrw folders vanish and lose trailing slash in tree-view after focus gained (Issue #9807)

33 views
Skip to first unread message

Mirko Palmer

unread,
Feb 20, 2022, 8:28:23 AM2/20/22
to vim/vim, Subscribed

Steps to reproduce

  1. build latest master with default configure options

  2. set minimal vimrc

set nocompatible

let g:netrw_liststyle=3

  1. have test folder structure
~/a

  └── b

      ├── c

      ├── c2

      └── c3

          └── d

  1. open netrw in folder a:
:Lexplore a

  1. enter folder b
  2. enter folder c3 and have this tree (header omitted):
../

a/

| b/

| | c/

| | c2/

| | c3/

| | | d/

  1. De-select the terminal (lose focus)

  2. Select vim again (regain focus)

  3. See this (header omitted again):

../

a/

| b/

| | c

| | c2

| | c3

(Clicking those folders without slashes opens another netrw view with that folder as root - but that part is, in that broken state, technically correct I would say)

Note: it only happens when you are "3 folders deep" - without opening 'd' it does not break.
Note2: Closing and re-opening folder 'b' "fixes" it - until the next focus lost/regain cycle.

Expected behaviour

Folders should not lose their trailing slash or vanish :)

Version of Vim

8.2.4424

Environment

Tested on Darwin arm (macos 12.2.1) and Ubuntu 21.04
xterm-256color
zsh 5.8

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9807@github.com>

Shfty

unread,
Mar 21, 2023, 3:36:10 PM3/21/23
to vim/vim, Subscribed

Is this likely to be looked at any time soon?

This has been a persistent issue with my workflow for a good while now, and is getting to the point where discarding netrw in favour of NERDtree maximalism is the only sane way to explore my source tree from within vim.


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/9807/1478473570@github.com>

Bram Moolenaar

unread,
Apr 19, 2023, 5:30:08 PM4/19/23
to vim/vim, Subscribed

ping @cecamp


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/9807/1515409002@github.com>

juanig1

unread,
May 7, 2023, 8:55:26 PM5/7/23
to vim/vim, Subscribed

Hey,

(This has been on my list for a while, I remember encountering this a couple of years ago
when getting into Vim and trying to get it to look like my IDE at that time.)

Seems there is an issue in the glob wrapper used to refresh the tree after focus is regained: NetrwGlob.

When a pattern matches a folder, (in this case '*') it is returned without a trailing slash.
However, we expect the slash to be there when iterating entries to render subfolders here.

Following the original example:
all c*/ subfolders become c* (no slash) in the dictionary after refresh, causing them to be treated as files.

For the initial example, initial dictionary entries are:

{'a/b/c3': ['d/'], 'a': ['b/'], 'a/b': ['c/', 'c2/', 'c3/']}

And after a refresh we get:

{'a/b/c3': ['d/'], 'a': ['b/'], 'a/b': ['c', 'c2', 'c3', '.', '..']}

I'm pretty out of touch with Vim script (and source) but, to be more clear, a naive patch addressing it may look like this:
(parent folder substitution needs a small tweak to handle trailing slashes)

diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim
index 1372de4df..c4870ce3c 100644
--- a/runtime/autoload/netrw.vim
+++ b/runtime/autoload/netrw.vim
@@ -5821,13 +5821,16 @@ fun! s:NetrwGlob(direntry,expr,pare)
    let w:netrw_liststyle= keep_liststyle
   elseif v:version > 704 || (v:version == 704 && has("patch656"))
    let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
+   let filelist = map(filelist, 'isdirectory(v:val) && v:val !~ "\\.\\.$" && v:val !~ "\\.$" ? v:val . "/" : v:val')
    if a:pare
-    let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
+    let parentdir=fnameescape(a:direntry).'/'
+    let filelist= map(filelist,'substitute(v:val, parentdir, "", "")')
    endif
   else
    let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
    if a:pare
-    let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
+    let parentdir=fnameescape(a:direntry).'/'
+    let filelist= map(filelist,'substitute(v:val, parentdir, "", "")')
    endif
   endif
 "  call Dret("s:NetrwGlob ".string(filelist))

Two things that may be worth mentioning but not entirely related:

  • glob() returns the list sorted alphabetically (without slashes), so re-sorting may be need (subtree b/ a c will change to a b/ c after a refresh)
  • refreshing causes expanded empty folders ('' child entry) to collapse and need the same 'closing and reopening' treatment to work properly.

Let me know if I can help with anything!


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/9807/1537593854@github.com>

cecamp

unread,
May 9, 2023, 5:09:57 AM5/9/23
to vim/vim, Subscribed

Hmm, with my usual options I don't see that misbehavior; I have to run it without my .vimrc to see it. I'll look into it further.


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/9807/1539406307@github.com>

cecamp

unread,
May 9, 2023, 5:09:58 AM5/9/23
to vim/vim, Subscribed

First finding: the option I use which prevents the issue is:
let g:netrw_fastbrowse= 2
That shouldn't be a problem for the normal setting, so I'll look into it further, but at least you can use that setting for now.


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/9807/1539415211@github.com>

juanig1

unread,
May 9, 2023, 3:42:40 PM5/9/23
to vim/vim, Subscribed

First finding: the option I use which prevents the issue is:
let g:netrw_fastbrowse= 2

Great!

Just a heads up: seems to still be reproducible with let g:netrw_fastbrowse= 2 if we
follow the original report until step 6 and instead of changing focus, we force a refresh with ctrl-L.


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/9807/1540792856@github.com>

Mirko Palmer

unread,
Jun 24, 2023, 6:04:52 AM6/24/23
to vim/vim, Subscribed

My two cents:

  • Instead of tweaking s:NetrwGlob(), f_glob() itself technically has a WILD_ADD_SLASH flag, which I think may be cleaner and solves a big part of the issue - though, it would probably have to be add as another parameter to glob().

  • The sorting of glob is very much an issue: if you have any g:netrw_sort_sequence set, the glob will alter and break the order.
    Unfortunately I fail to create any combination of hackery to re-sort the tree after the globbing produced by a refresh.
    (I was toying around with s:NetrwSetSort and the exe '$sort [...] but I am clearly doing something wrong - netrw is a complex beast)

  • Lastly, and this is 100% pebcac: the fastbrowse= 2 option is no solution for me, since I have to be able to refresh the list, due to some other hackery in my config.


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/9807/1605351626@github.com>

Christian Brabandt

unread,
Nov 7, 2024, 3:34:24 PM11/7/24
to vim/vim, Subscribed

Closed #9807 as completed via 64a536d.


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/9807/issue_event/15192581587@github.com>

Reply all
Reply to author
Forward
0 new messages