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:
Steven Arcangeli 2023-08-20 00:40:24 +00:00
parent 8f7807946a
commit 9d90893c37
5 changed files with 20 additions and 38 deletions

5
.github/generate.py vendored
View file

@ -73,10 +73,11 @@ def update_readme_toc():
def update_config_options():
config_file = os.path.join(ROOT, "lua", "oil", "config.lua")
opt_lines = read_section(config_file, r"^\s*local default_config =", r"^}$")
opt_lines = ['\n```lua\nrequire("oil").setup({\n']
opt_lines.extend(read_section(config_file, r"^\s*local default_config =", r"^}$"))
replace_section(
README,
r"^require\(\"oil\"\)\.setup\(\{$",
r"^## Options$",
r"^}\)$",
opt_lines,
)

View file

@ -114,7 +114,7 @@ Then open a directory with `nvim .`. Use `<CR>` to open a file/directory, and `-
If you want to mimic the `vim-vinegar` method of navigating to the parent directory of a file, add this keymap:
```lua
vim.keymap.set("n", "-", require("oil").open, { desc = "Open parent directory" })
vim.keymap.set("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })
```
You can open a directory with `:edit <path>` or `:Oil <path>`. To open oil in a floating window, do `:Oil --float <path>`.
@ -123,6 +123,9 @@ You can open a directory with `:edit <path>` or `:Oil <path>`. To open oil in a
```lua
require("oil").setup({
-- 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 = {
@ -147,8 +150,6 @@ require("oil").setup({
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
@ -331,12 +332,3 @@ If you don't need those features specifically, check out the alternatives listed
- [vidir](https://github.com/trapd00r/vidir): Never personally used, but might be the first plugin to come up with the idea of editing a directory like a buffer.
There's also file trees like [neo-tree](https://github.com/nvim-neo-tree/neo-tree.nvim) and [nvim-tree](https://github.com/nvim-tree/nvim-tree.lua), but they're really a different category entirely.
**Q: I don't need netrw anymore. How can I disable it?**
**A:** Oil can fully replace netrw for local and ssh file browsing/editing, but keep in mind that netrw also supports rsync, http, ftp, and dav. If you don't need these other features, you can disable netrw with the following:
```lua
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
```

View file

@ -14,6 +14,9 @@ OPTIONS *oil-option
>
require("oil").setup({
-- 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 = {
@ -38,8 +41,6 @@ OPTIONS *oil-option
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

View file

@ -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

View file

@ -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,