Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: no alternate file #60

Closed
3 tasks done
WhoIsSethDaniel opened this issue Feb 23, 2023 · 7 comments
Closed
3 tasks done

bug: no alternate file #60

WhoIsSethDaniel opened this issue Feb 23, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@WhoIsSethDaniel
Copy link

Did you check the docs and existing issues?

  • I have read the docs
  • I have searched the existing issues

Neovim version (nvim -v)

v0.9.0-dev-1028+gd422fc827

Operating system/version

Ubuntu Kinetic

Describe the bug

Appears to be a regression of #43 and #20, perhaps.
I have a keymap of '-' to "require('oil').open". If I open a file, press '-' to get the file listing for the current directory, and then press C-6 (or C-^) I get an error: "No alternate file".

Steps To Reproduce

  1. nvim somefile.txt
  2. :lua require('oil').open()
  3. C-6 -> E23: No alternate file

Expected Behavior

Pressing C-6 returns to previous file. This should be regardless of how many times I press '-' or use open(). I should be able to return from oil to my previous file by pressing C-6.

Directory structure

No response

Repro

-- 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
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
        "stevearc/oil.nvim",
        config = function()
            require("oil").setup({
              -- add any needed settings here
            })
        end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Did you check the bug with a clean config?

  • I have confirmed that the bug reproduces with nvim -u repro.lua using the repro.lua file above.
@WhoIsSethDaniel WhoIsSethDaniel added the bug Something isn't working label Feb 23, 2023
@WhoIsSethDaniel
Copy link
Author

WhoIsSethDaniel commented Feb 23, 2023

Here's a reproducible scenario where the alternate file is set appropriately:

  1. nvim
  2. :e somefile
  3. :lua require('oil').open()
  4. C-6

However, I think this scenario, while it has an alternate file, sets it incorrectly:

  1. nvim
  2. :e somefile1
  3. :lua require('oil').open() -- somefile1 is set as alternate
  4. navigate to another file somefile2, and edit it -- somefile1 is set as alternate
  5. :lua require('oil').open() -- somefile1 continues to be the alternate, but should be somefile2

Ideally in the second scenario this should happen:

  1. nvim
  2. :e somefile1
  3. :lua require('oil').open() -- somefile1 is set as alternate
  4. use oil to navigate to another file somefile2, and edit it -- somefile1 is set as alternate
  5. :lua require('oil').open() -- somefile2 is the alternate
  6. use oil to navigate to somefile2 again, and edit it -- somefile1 is again alternate

@stevearc
Copy link
Owner

The repro was very helpful, thanks! I added a test for that condition and made some changes until it passed. Can you see if it's working as expected now?

@WhoIsSethDaniel
Copy link
Author

This is working correctly. Thank you!

@WhoIsSethDaniel
Copy link
Author

WhoIsSethDaniel commented Feb 24, 2023

I wasn't certain whether I should open a new bug or just reopen this bug. I have found two new scenarios where the alternate file goes missing.

  1. nvim somefile.txt
  2. :lua require('oil').open() -- somfile.txt is alternate
  3. navigate to a subdirectory -- no file is alternate

In the above scenario if you navigate to a parent directory the alternate is saved, but once you navigate to any subdirectory of any other directory the alternate file is lost. However, if you then navigate to a parent directory the alternate file returns.

Also this:

  1. nvim somefile.txt
  2. :lua require('oil').open() -- somefile.txt is alternate
  3. preview a file in the directory -- no file is alternate
  4. remove preview -- no file is alternate

@stevearc
Copy link
Owner

stevearc commented Mar 6, 2023

Thanks for the report! Those should be handled now as well

@iovis
Copy link
Contributor

iovis commented Jan 17, 2024

I seem to have this issue (no alternate) when opening with :Oil --float, it seems to work fine without --float

@stevearc
Copy link
Owner

@iovis if you're still seeing issues with this please file it with a repro as a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants