mikavilpas / yazi.nvim

A Neovim Plugin for the yazi terminal file manager
MIT License
214 stars 7 forks source link

fix: open file results in one empty buffer #138

Closed rick-yao closed 5 days ago

rick-yao commented 6 days ago

I am using AstroNvim and encountered an issue that will result in one empty buffer. background: AstroNvim uses alpha.nvim as a greeting. reproduce procedure:

  1. use astronvim
  2. add yazi.nvim with below config
    ---@type LazySpec
    return {
    "mikavilpas/yazi.nvim",
    event = "VeryLazy",
    keys = {
    -- 👇 in this section, choose your own keymappings!
    {
      "<leader>-",
      function() require("yazi").yazi() end,
      desc = "Open the file manager",
    },
    {
      -- Open in the current working directory
      "<leader>+",
      function() require("yazi").yazi(nil, vim.fn.getcwd()) end,
      desc = "Open the file manager in nvim's working directory",
    },
    },
    ---@type YaziConfig
    opts = {
    -- open_for_directories = true,
    log_level = vim.log.levels.INFO,
    },
    }
  3. open neovim , leader- to open yazi,select a file to open
  4. will look like below ,an Untitled buffer is created. image

I added a temporary solution to fix it which is ugly because I did not find why this happened. If you'd like to help, I'd like to pr further. My solution is to find the buffer with no actual path. If the path is empty , then delete the buffer.

minimum repro lua with astronvim nvim -u repro.lua to use

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")

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

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  -- stylua: ignore
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable",
    lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)

-- install plugins
local plugins = {
  { "AstroNvim/AstroNvim", import = "astronvim.plugins" },
  {
    "mikavilpas/yazi.nvim",
    event = "VeryLazy",
    keys = {
      -- 👇 in this section, choose your own keymappings!
      {
        "<leader>-",
        function()
          require("yazi").yazi()
        end,
        desc = "Open the file manager",
      },
      {
        -- Open in the current working directory
        "<leader>+",
        function()
          require("yazi").yazi(nil, vim.fn.getcwd())
        end,
        desc = "Open the file manager in nvim's working directory",
      },
    },
    ---@type YaziConfig
    opts = {
      -- open_for_directories = true,
      log_level = vim.log.levels.INFO,
    },
  },

  -- add any other plugins/customizations here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- add anything else here (autocommands, vim.filetype, etc.)
mikavilpas commented 6 days ago

Thanks, I appreciate the effort you put in! I can reproduce the issue, and I'll try to find the root cause.

mikavilpas commented 5 days ago

Thanks again for pointing this out. I was able to fix it for my lazyvim setup as well as the astronvim repro setup you provided 👍🏻

rick-yao commented 3 days ago

Thanks so much for your quick fix!