Re: [vim/vim] Traversing directories in netrw quickly creates (and immediately deletes) swap files, changing the directories lastModifiedTime (Issue #18854)

12 views
Skip to first unread message

Christian Brabandt

unread,
Dec 3, 2025, 2:23:51 AM12/3/25
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#18854)

Changing the default value for 'directory' seems a bit drastic and is out of the question, as that has other unwanted effects (e.g. when several users edit the same file you won't notice it). The correct way is to configure your 'directory' setting as you did already.

It might be possible to modify netrw to not create swapfiles. I do not know offhand, if this is really possible, it could be that swapfiles will be created anyhow and disabling swapfiles within netrw might come too late, not sure yet.


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/18854/3605442268@github.com>

David Alayachew

unread,
Dec 3, 2025, 4:17:54 AM12/3/25
to vim/vim, Subscribed
davidalayachew left a comment (vim/vim#18854)

Thanks for the speedy response @chrisbra. I definitely didn't consider the multiple users point, ty vm.

It would be good if we could avoid creating swapfiles just for netrw. Though, I am more surprised that we make any in the first place.

Why does netrw make swapfiles? Through all the study and research that we did (in the linked StackExchange post), we were never able to catch the file long enough to read its contents.


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/18854/3605840880@github.com>

Christian Brabandt

unread,
Dec 3, 2025, 6:18:00 AM12/3/25
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#18854)

this is just a guess, I only had a quick look. Can you try this patch?

diff --git a/runtime/pack/dist/opt/netrw/autoload/netrw.vim b/runtime/pack/dist/opt/netrw/autoload/netrw.vim
index 5aa087afb..af58267fa 100644
--- a/runtime/pack/dist/opt/netrw/autoload/netrw.vim
+++ b/runtime/pack/dist/opt/netrw/autoload/netrw.vim
@@ -4256,12 +4256,12 @@ endfunction
 "    NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
 function s:NetrwEditFile(cmd,opt,fname)
     if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
-        exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
+        exe "NetrwKeepj noswapfile keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
     else
         if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
             call setbufvar(bufname('%'), '&bufhidden', 'hide')
         endif
-        exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
+        exe "NetrwKeepj noswapfile ".a:opt." ".a:cmd." ".fnameescape(a:fname)
     endif
 endfunction


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/18854/3606365820@github.com>

David Alayachew

unread,
Jan 15, 2026, 7:42:50 AM (20 hours ago) Jan 15
to vim/vim, Subscribed
davidalayachew left a comment (vim/vim#18854)

this is just a guess, I only had a quick look. Can you try this patch?

diff --git a/runtime/pack/dist/opt/netrw/autoload/netrw.vim b/runtime/pack/dist/opt/netrw/autoload/netrw.vim
index 5aa087afb..af58267fa 100644
--- a/runtime/pack/dist/opt/netrw/autoload/netrw.vim
+++ b/runtime/pack/dist/opt/netrw/autoload/netrw.vim
@@ -4256,12 +4256,12 @@ endfunction
 "    NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
 function s:NetrwEditFile(cmd,opt,fname)
     if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
-        exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
+        exe "NetrwKeepj noswapfile keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
     else
         if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
             call setbufvar(bufname('%'), '&bufhidden', 'hide')
         endif
-        exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
+        exe "NetrwKeepj noswapfile ".a:opt." ".a:cmd." ".fnameescape(a:fname)
     endif
 endfunction

Sorry for the delayed responses -- holidays.

How do I try this patch? Is there a build I download? Or is this a file that I have to edit in my workspace?


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/18854/3754557422@github.com>

Christian Brabandt

unread,
Jan 15, 2026, 3:47:57 PM (12 hours ago) Jan 15
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#18854)

Okay, if you are not familiar with patches, let try to do it manually, that patch is not that hard to read. In principle you need to find the lines marked with a leading - and replace them with the line marked with a leading +. In your case, from within Vim try to edit :e $VIMRUNTIME/pack/dist/opt/netrw/autoload/netrw.vim then go to line 4256 (:4256) and add those 2 NetrwKeepj lines by adding the noswapfile modifier to it.
Depending on your system, you may need to run vim with admin privileges in order to edit a file within $VIMRUNTIME.


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/18854/3756793376@github.com>

David Alayachew

unread,
Jan 15, 2026, 5:07:18 PM (11 hours ago) Jan 15
to vim/vim, Subscribed
davidalayachew left a comment (vim/vim#18854)

Okay, if you are not familiar with patches, let try to do it manually, that patch is not that hard to read. In principle you need to find the lines marked with a leading - and replace them with the line marked with a leading +. In your case, from within Vim try to edit :e $VIMRUNTIME/pack/dist/opt/netrw/autoload/netrw.vim then go to line 4256 (:4256) and add those 2 NetrwKeepj lines by adding the noswapfile modifier to it.
Depending on your system, you may need to run vim with admin privileges in order to edit a file within $VIMRUNTIME.

It worked! Ty vm. I only did some initial testing with it, but so far, no issues.


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/18854/3757107843@github.com>

Reply all
Reply to author
Forward
0 new messages