From c318da73b49395a9fb1f75de55704fb080a539bd Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Sat, 13 Sep 2025 02:00:52 +0900 Subject: [PATCH] vim-patch:5346688: runtime(netrw): fix :Explore command in terminal There are really two issues solved here: - The directory listing was not populating the new buffer when using the :Explore command. This was because the directory to open is determined by using expand("%:p") which includes '!/running/command' at the end of the string in terminal buffers. - The :Explore command should replace the buffer, not split it. This because the Explore command will automatically split if the current buffer has been modified. According to the docs, all terminal buffers will have the modified flag set when a job is running. fixes: vim/vim#9862 closes: vim/vim#18069 https://github.com/vim/vim/commit/53466887f71f47ae74227a69ba15120e5f9a161b Co-authored-by: Jason Long --- runtime/pack/dist/opt/netrw/autoload/netrw.vim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/runtime/pack/dist/opt/netrw/autoload/netrw.vim b/runtime/pack/dist/opt/netrw/autoload/netrw.vim index 1ebbf1aa81..e0b6ec26ef 100644 --- a/runtime/pack/dist/opt/netrw/autoload/netrw.vim +++ b/runtime/pack/dist/opt/netrw/autoload/netrw.vim @@ -4,6 +4,7 @@ " Last Change: " 2025 Aug 07 by Vim Project (use correct "=~#" for netrw_stylesize option #17901) " 2025 Aug 07 by Vim Project (netrw#BrowseX() distinguishes remote files #17794) +" 2025 Aug 22 by Vim Project netrw#Explore handle terminal correctly #18069 " Copyright: Copyright (C) 2016 Charles E. Campbell {{{1 " Permission is hereby granted to use and distribute this code, " with or without modifications, provided that this copyright @@ -430,10 +431,13 @@ function netrw#Explore(indx,dosplit,style,...) " record current directory let curdir = simplify(b:netrw_curdir) - let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e') if !exists("g:netrw_cygwin") && has("win32") let curdir= substitute(curdir,'\','/','g') endif + let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e') + if &buftype == "terminal" + let curfiledir = curdir + endif " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea) " will end up with backslashes here. Solution: strip off backslashes that precede white space and @@ -456,9 +460,9 @@ function netrw#Explore(indx,dosplit,style,...) sil! let keepregslash= @/ " if dosplit - " -or- file has been modified AND file not hidden when abandoned + " -or- buffer is not a terminal AND file has been modified AND file not hidden when abandoned " -or- Texplore used - if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6 + if a:dosplit || (&buftype != "terminal" && &modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6 call s:SaveWinVars() let winsz= g:netrw_winsize if a:indx > 0