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] restore from path argument incompatible with oil.nvim #372

Closed
niderhoff opened this issue Sep 2, 2024 · 6 comments
Closed

[BUG] restore from path argument incompatible with oil.nvim #372

niderhoff opened this issue Sep 2, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@niderhoff
Copy link

Describe the bug
Trying to restore a session from a path argument like this:

nvim /my_folder/

will fail, because it is compatible, with oil.nvim, because the latter is rewriting the argument from /my_folder/ to oil:///my_folder.

To Reproduce
Steps to reproduce the behavior:

  1. save a session in /my_folder
  2. Install oil.nvim
  3. run nvim /my_folder/
  4. session is not restored, instead oil file explorer is started

Expected behavior
Session is restored.

Screenshots
Before oil.nvim:

image

after:

image

Checkhealth
image

Baseline (please complete the following information):

  • sessionoptions=blank,buffers,curdir,folds,help,tabpages,winsize,terminal
  • Darwin T000fad6c4 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 arm64
  • NVIM v0.10.1

Additional context

@niderhoff niderhoff added the bug Something isn't working label Sep 2, 2024
@niderhoff niderhoff changed the title [BUG] restore from path argument incompatible with oil.vnim [BUG] restore from path argument incompatible with oil.nvim Sep 2, 2024
@cameronr
Copy link
Collaborator

cameronr commented Sep 2, 2024

I use oil as well and I think the trick is to make sure it's lazy loaded until after the session is restored. What does your oil config look like?

For mine, i set keys:

return {
  'stevearc/oil.nvim',
  keys = {
    {
      '<Bslash><Bslash>',
      function() require('oil').toggle_float() end,
      desc = 'Oil popup',
    },
  },
...

@niderhoff
Copy link
Author

niderhoff commented Sep 2, 2024

@cameronr

return {
    "stevearc/oil.nvim",
    opts = {},
    dependencies = { "nvim-tree/nvim-web-devicons" },
    config = function()
        require("oil").setup({
            default_file_explorer = true,
            delete_to_trash = true,
            skip_confirm_for_simple_edits = false,
            view_options = {
                show_hidden = false,
                natural_order = true,
                is_always_hidden = function(name, _)
                    return name == '..' or name == '.git'
                end,
            },
            win_options = {
                wrap = true,
            }
        })
    end,
}

its probably due to default_file_explorer ?

@cameronr
Copy link
Collaborator

cameronr commented Sep 2, 2024

Shouldn't depend on default_file_explorer (i have that in mine as well). What key do you use to open oil / how do you open it?

Or you can try my config:

return {
  'stevearc/oil.nvim',

  keys = {
    {
      '<Bslash><Bslash>',
      function() require('oil').toggle_float() end,
      desc = 'Oil',
    },
  },
  opts = {
    default_file_explorer = true,
    delete_to_trash = true,
    skip_confirm_for_simple_edits = false,
    view_options = {
      show_hidden = true,
      natural_order = true,
      is_always_hidden = function(name, _) return name == '..' or name == '.git' end,
    },
    float = {
      padding = 2,
      max_width = 90,
      max_height = 0,
    },
    win_options = {
      wrap = true,
      winblend = 0,
    },
    keymaps = {
      ['<C-c>'] = false,
      ['q'] = 'actions.close',
      ['<Esc>'] = 'actions.close',
    },
  },
}

With the keys block, oil isn't loaded until I press \\ so it doesn't interfere when launching nvim with a directory argument.

@cameronr
Copy link
Collaborator

cameronr commented Sep 7, 2024

@niderhoff are you still running into problems or did this resolve it for you?

@niderhoff
Copy link
Author

I tried again and now it behaves like this (without errors):

nvim -> restore session
nvim . -> start oil
nvim some_folder -> start oil

it is what I would expected it to behave, but maybe we should update readme to indicate that if something hooks into default_file_explorer (such as oil, or neotree) it might mean that behaviour 2:

When starting nvim . (or another directory), AutoSession will try to restore the session for that directory.

will instead open the file explorer.

@cameronr
Copy link
Collaborator

I'll take a look at the docs and see if I can clarify a bit.

If you want nvim . to be processed by auto-session instead of oil, you can lazy load oil:

return {
    "stevearc/oil.nvim",
     -- setting cmd/keys will cause Lazy.nvim to only load Oil when on that cmd or key press
     cmd = 'Oil',
     keys = {
          {
               '<Bslash><Bslash>', -- or whatever key you want to trigger oil
               function() require('oil').toggle_float() end, -- or however you want it to be displayed
               desc = 'Oil',
         },
      },
    -- opts = {}, -- setting opts doesn't do anything if you're using a custom config function so this line can be removed
    dependencies = { "nvim-tree/nvim-web-devicons" },
    config = function()
        require("oil").setup({
            default_file_explorer = true,
            delete_to_trash = true,
            skip_confirm_for_simple_edits = false,
            view_options = {
                show_hidden = false,
                natural_order = true,
                is_always_hidden = function(name, _)
                    return name == '..' or name == '.git'
                end,
            },
            win_options = {
                wrap = true,
            }
        })
    end,
}

If you want oil to load for a directory if there's no existing session, you could also add this to your auto-session config:

return {
  'rmagatti/auto-session',
  lazy = false,
  ...
  ---@module "auto-session"
  ---@type AutoSession.Config
  opts = {
    ...
    no_restore_cmds = {
      function()
        -- load oil in case we're launching with a dir arg and there's no session
        require('oil')
      end,
    },
  },
}

cameronr added a commit to cameronr/auto-session that referenced this issue Nov 12, 2024
cameronr added a commit that referenced this issue Nov 18, 2024
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