Skip to content

runtime(netrw): Fixing global variable initialization on Windows#19287

Open
MiguelBarro wants to merge 3 commits intovim:masterfrom
MiguelBarro:netrw-init
Open

runtime(netrw): Fixing global variable initialization on Windows#19287
MiguelBarro wants to merge 3 commits intovim:masterfrom
MiguelBarro:netrw-init

Conversation

@MiguelBarro
Copy link
Contributor

@MiguelBarro MiguelBarro commented Jan 30, 2026

Some default options are initialized as empty:

" Default option values: {{{2
call s:NetrwInit("g:netrw_localcopycmdopt","")
call s:NetrwInit("g:netrw_localcopydircmdopt","")
call s:NetrwInit("g:netrw_localmkdiropt","")
call s:NetrwInit("g:netrw_localmovecmdopt","")

preventing them later from getting the rigth value:
if !exists("g:netrw_localmovecmd")
if has("win32")
if g:netrw_cygwin
let g:netrw_localmovecmd= "mv"
else
let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
call s:NetrwInit("g:netrw_localmovecmdopt"," /c move")

because s:NetrwInit() will only set values for undefined variables:
function s:NetrwInit(name, default)
if !exists(a:name)
let {a:name} = a:default
endif
endfunction

After the fix, things were not working so I revamp those functions where the default options were used. Besides:

  • Copying several files with a single command is not possible on Windows and was broken.
  • The code ignored issues associated with the shellslash option.
  • I've extended the netrw testing accordingly.

Signed-off-by: Guybrush <miguel.barro@live.com>
@MiguelBarro MiguelBarro marked this pull request as draft February 1, 2026 16:56
Signed-off-by: Guybrush <miguel.barro@live.com>
@MiguelBarro MiguelBarro marked this pull request as ready for review February 2, 2026 01:16
@chrisbra chrisbra requested a review from Copilot February 4, 2026 16:38
@chrisbra
Copy link
Member

chrisbra commented Feb 4, 2026

Thanks. I am a bit unsure, whether or not to consider this for the Vim 9.2 release. I'll probably move it to after the release, as this is currently too much to review with confidence

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes global variable initialization issues in the netrw plugin on Windows. The core problem was that default option variables were initialized as empty strings early in the script, preventing platform-specific values from being set later. The PR restructures initialization to properly detect the platform and set appropriate commands for Windows (using cmd.exe with COMSPEC) versus Unix systems. Additionally, it fixes shellslash handling throughout file operations and significantly expands test coverage for file management functions across different shells (default, PowerShell, and pwsh).

Changes:

  • Restructured initialization of netrw global variables to properly set Windows-specific commands
  • Fixed shellslash option handling in path composition and file operations
  • Added comprehensive test infrastructure and coverage for file operations (mkdir, copy, move) across multiple shells

Reviewed changes

Copilot reviewed 1 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/testdir/test_plugin_netrw.vim Extensively refactored test infrastructure with new test helpers, added SetUp/TearDown functions, and comprehensive tests for file operations across different shells
runtime/pack/dist/opt/netrw/autoload/netrw/fs.vim Fixed ComposePath to respect shellslash option when choosing path separator
runtime/pack/dist/opt/netrw/autoload/netrw.vim Restructured global variable initialization, updated file copy/move operations to handle Windows properly and respect shellslash, simplified error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Guybrush <miguel.barro@live.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants