-
Notifications
You must be signed in to change notification settings - Fork 200
Description
Describe the bug
On Windows, oil.nvim fails to select the current file when opening if the buffer's path uses forward slashes (e.g., C:/Users/...) instead of backslashes. This is because the os_to_posix_path function in lua/oil/fs.lua only handles paths with backslashes when converting a Windows path to a POSIX-like path.
To Reproduce
- On Windows, open a file in Neovim where the path is represented with forward slashes.
- Run
:Oil. oil.nvimopens the directory but fails to select the current file, defaulting to the first entry.
Expected behavior
oil.nvim should correctly parse the path and select the active file regardless of whether the path uses forward or backslashes.
Fix
The os_to_posix_path function was updated to be more robust. The corrected version first normalizes all backslashes to forward slashes and then correctly parses the drive letter.
Here is the code for the fix:
---@param path string
---@return string
M.os_to_posix_path = function(path)
if M.is_windows then
local p = path:gsub("\\", "/")
if p:match("^%a:/") then
local drive, rem = p:match("^([^:]+):/(.*)$")
return string.format("/%s/%s", drive:upper(), rem)
else
return p
end
else
return path
end
endThis change ensures that paths like C:\path and C:/path are both handled correctly.