refactor!: disable netrw by default (#155)
If you use oil and you want to still use netrw, set `default_file_explorer = false`. It is nonsensical to both use netrw _and_ have oil hijack directory buffers (which was the case for the default config). It also causes undefined behavior and bugs. When `default_file_explorer = true` (the default) oil will now disable netrw for you.
This commit is contained in:
parent
8f7807946a
commit
9d90893c37
5 changed files with 20 additions and 38 deletions
|
|
@ -1,4 +1,7 @@
|
|||
local default_config = {
|
||||
-- Oil will take over directory buffers (e.g. `vim .` or `:e src/`)
|
||||
-- Set to false if you still want to use netrw.
|
||||
default_file_explorer = true,
|
||||
-- Id is automatically added at the beginning, and name at the end
|
||||
-- See :help oil-columns
|
||||
columns = {
|
||||
|
|
@ -23,8 +26,6 @@ local default_config = {
|
|||
conceallevel = 3,
|
||||
concealcursor = "n",
|
||||
},
|
||||
-- Oil will take over directory buffers (e.g. `vim .` or `:e src/`
|
||||
default_file_explorer = true,
|
||||
-- Restore window options to previous values when leaving an oil buffer
|
||||
restore_win_options = true,
|
||||
-- Skip the confirmation popup for simple operations
|
||||
|
|
|
|||
|
|
@ -846,8 +846,13 @@ M.setup = function(opts)
|
|||
end, { desc = "Open oil file browser on a directory", nargs = "*", complete = "dir" })
|
||||
local aug = vim.api.nvim_create_augroup("Oil", {})
|
||||
|
||||
if config.default_file_explorer and vim.fn.exists("#FileExplorer") then
|
||||
vim.api.nvim_create_augroup("FileExplorer", { clear = true })
|
||||
if config.default_file_explorer then
|
||||
vim.g.loaded_netrw = 1
|
||||
vim.g.loaded_netrwPlugin = 1
|
||||
-- If netrw was already loaded, clear this augroup
|
||||
if vim.fn.exists("#FileExplorer") then
|
||||
vim.api.nvim_create_augroup("FileExplorer", { clear = true })
|
||||
end
|
||||
end
|
||||
|
||||
local patterns = {}
|
||||
|
|
@ -967,24 +972,6 @@ M.setup = function(opts)
|
|||
end,
|
||||
})
|
||||
end
|
||||
if
|
||||
vim.g.loaded_netrwPlugin ~= 1
|
||||
and not config.silence_netrw_warning
|
||||
and config.default_file_explorer
|
||||
then
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
desc = "Inform user how to disable netrw",
|
||||
group = aug,
|
||||
pattern = "netrw",
|
||||
once = true,
|
||||
callback = function()
|
||||
vim.notify(
|
||||
"If you expected an Oil buffer here, you may want to disable netrw (:help netrw-noload)\nSet `default_file_explorer = false` in oil.setup() to not take over netrw buffers, or `silence_netrw_warning = true` to disable this message.",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
end,
|
||||
})
|
||||
end
|
||||
vim.api.nvim_create_autocmd("WinNew", {
|
||||
desc = "Restore window options when splitting an oil window",
|
||||
group = aug,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue