summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2026-04-23 08:57:47 +0800
committerzeertzjq <zeertzjq@outlook.com>2026-04-23 12:51:11 +0800
commitd6cdd04223a76ea7f4e6b1f6156a64d67eae774d (patch)
treef0fefab665e1198d3b6e97820938ba773f5462cb
parentde68ec4f4928ef089cb271e0da0d2116c2a4b7da (diff)
vim-patch:9.2.0367: runtime(netrw): ~ note expanded on MS Windows
Problem: runtime(netrw): ~ note expanded on MS Windows (Tom Vamvanij) Solution: Expand ~ on MS Windows (Yasuhiro Matsumoto) On Windows, ":Explore ~" did nothing because the tilde expansion was gated to Unix/Cygwin only. Additionally, substitute() interprets backslashes in the replacement string specially (e.g. \U as a case modifier), which would corrupt $HOME values like C:\Users\name even if the branch were taken. Include has("win32") in the guard, anchor the pattern to the start of the string, and escape backslashes, ampersands and tildes in $HOME before substituting. fixes: vim/vim#20003 closes: vim/vim#20014 https://github.com/vim/vim/commit/723c0acf2535c87a5b7be0284e7379e071a1d610 Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
-rw-r--r--runtime/pack/dist/opt/netrw/autoload/netrw.vim5
-rw-r--r--test/old/testdir/test_plugin_netrw.vim6
2 files changed, 9 insertions, 2 deletions
diff --git a/runtime/pack/dist/opt/netrw/autoload/netrw.vim b/runtime/pack/dist/opt/netrw/autoload/netrw.vim
index 1deda534d2..6226c5b51f 100644
--- a/runtime/pack/dist/opt/netrw/autoload/netrw.vim
+++ b/runtime/pack/dist/opt/netrw/autoload/netrw.vim
@@ -25,6 +25,7 @@
" 2026 Apr 01 by Vim Project use fnameescape() with netrw#FileUrlEdit()
" 2026 Apr 05 by Vim Project Fix netrw#RFC2396() #19913
" 2026 Apr 15 by Vim Project Add missing escape()
+" 2026 Apr 19 by Vim Project expand ~ on Windows #20003
" 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
@@ -530,8 +531,8 @@ function netrw#Explore(indx,dosplit,style,...)
NetrwKeepj norm! 0
if a:0 > 0
- if a:1 =~ '^\~' && (has("unix") || g:netrw_cygwin)
- let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
+ if a:1 =~ '^\~' && (has("unix") || has("win32") || g:netrw_cygwin)
+ let dirname= simplify(substitute(a:1,'^\~',escape(expand("$HOME"),'\&~'),''))
elseif a:1 == '.'
let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
if dirname !~ '/$'
diff --git a/test/old/testdir/test_plugin_netrw.vim b/test/old/testdir/test_plugin_netrw.vim
index c33b3c307e..83b2d969f6 100644
--- a/test/old/testdir/test_plugin_netrw.vim
+++ b/test/old/testdir/test_plugin_netrw.vim
@@ -616,4 +616,10 @@ func Test_netrw_RFC2396()
call assert_equal('a b', netrw#RFC2396(fname))
endfunc
+func Test_netrw_Home_tilde()
+ Explore ~
+ call assert_match('Netrw Directory Listing', getline(2))
+ bw!
+endfunc
+
" vim:ts=8 sts=2 sw=2 et