[BUG] restore from path argument incompatible with oil.nvim
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:
- save a session in
/my_folder - Install
oil.nvim - run
nvim /my_folder/ - session is not restored, instead
oilfile explorer is started
Expected behavior Session is restored.
Screenshots
Before oil.nvim:
after:
Checkhealth
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
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',
},
},
...
@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 ?
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.
@niderhoff are you still running into problems or did this resolve it for you?
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.
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,
},
},
}