Skip to content

[Bug] can't open files with path containing the $ character #556

@bryankenote

Description

@bryankenote

Description

Files with a path containing a $ character are not loaded in diffview. There are frontend routing frameworks that use the $ character for file-based routing.

Expected behavior

Files with a path containing a $ character can be viewed in diffview like any other file.

Actual behavior

Diffview seems to show the file under a path without the $ character. For example a file at the path $b/c would become b/c. Diffview will show this as a file that has been removed because it doesn't exist on disk. gf will show the error

File does not exist on disk: 'b/c'

Steps to reproduce

  1. mkdir -p a/\$b
  2. cd a
  3. git init
  4. touch \$b/c
  5. nvim \$b/c
  6. :DiffviewOpen
  7. gf

Health check

Output of :checkhealth diffview
==============================================================================
diffview: require("diffview.health").check()

Checking plugin dependencies ~
- OK nvim-web-devicons installed.

Checking VCS tools ~
- The plugin requires at least one of the supported VCS tools to be valid.
- OK Git found.
- OK Git is up-to-date. (2.48.1)
- WARNING Configured `hg_cmd` is not executable: 'hg'

Log info

Relevant info from :DiffviewLog
[ERROR 2025-02-19 11:41:32.311 -0800] ...cal/share/nvim/lazy/diffview.nvim/lua/diffview/utils.lua:42: File does not exist on disk: 'b/c'

Neovim version

NVIM v0.10.4
Build type: Release
LuaJIT 2.1.1713484068

Operating system and version

macOS Sonoma 14.4.1

Minimal config

-- #######################################
-- ### USAGE: nvim --clean -u mini.lua ###
-- #######################################

local root = vim.fn.stdpath("run") .. "/nvim/diffview.nvim"
local plugin_dir = root .. "/plugins"
vim.fn.mkdir(plugin_dir, "p")

for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

local plugins = {
  { "nvim-web-devicons", url = "https://github.com/nvim-tree/nvim-web-devicons.git" },
  { "diffview.nvim", url = "https://github.com/sindrets/diffview.nvim.git" },
  -- ##################################################################
  -- ### ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
  -- ##################################################################
}

for _, spec in ipairs(plugins) do
  local install_path = plugin_dir .. "/" .. spec[1]
  if vim.fn.isdirectory(install_path) ~= 1 then
    if spec.url then
      print(string.format("Installing '%s'...", spec[1]))
      vim.fn.system({ "git", "clone", "--depth=1", spec.url, install_path })
    end
  end
  vim.opt.runtimepath:append(spec.path or install_path)
end

require("diffview").setup({
  -- ##############################################################################
  -- ### ADD DIFFVIEW.NVIM CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE ###
  -- ##############################################################################
})

vim.opt.termguicolors = true
vim.cmd("colorscheme " .. (vim.fn.has("nvim-0.8") == 1 and "habamax" or "slate"))

-- ############################################################################
-- ### ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
-- ############################################################################

print("Ready!")

Activity

changed the title [-][Bug][/-] [+][Bug] can't open files with path containing the `$` character[/+] on Feb 19, 2025
bryankenote

bryankenote commented on Feb 19, 2025

@bryankenote
Author

local env_var = segments[i]:match("^%$(%S+)$")
if env_var then
segments[i] = uv.os_getenv(env_var) or env_var
end

So it looks this is looking for environment vars in the path and trying to replace them with it's value.

raine

raine commented on Jul 11, 2025

@raine

Is there a fix?

Diffing does not work for paths with $ in the filename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @raine@bryankenote

      Issue actions

        [Bug] can't open files with path containing the `$` character · Issue #556 · sindrets/diffview.nvim