feat(config): add default_to_float option (#173)
Problem: opening oil as a float requires users to remap every entry point (`-`, `:Oil`, startup autocmd) individually. There is no single flag to make float the default everywhere. Solution: add `default_to_float = false` to config. When `true`, `M.open()` delegates to `M.open_float()` (covers `:Oil` and all keymap invocations), and a `VimEnter` hook replaces the initial directory buffer with a float when starting Neovim on a directory (e.g. `nvim .`). No recursion risk — `open_float()` calls `vim.cmd.edit()` directly and never goes through `M.open()`. Based on: stevearc/oil.nvim#298
This commit is contained in:
parent
91f4b13810
commit
3fede7d809
4 changed files with 34 additions and 1 deletions
|
|
@ -474,6 +474,9 @@ end
|
|||
M.open = function(dir, opts, cb)
|
||||
opts = opts or {}
|
||||
local config = require('oil.config')
|
||||
if config.default_to_float then
|
||||
return M.open_float(dir, opts, cb)
|
||||
end
|
||||
local util = require('oil.util')
|
||||
local view = require('oil.view')
|
||||
local parent_url, basename = M.get_url_for_path(dir)
|
||||
|
|
@ -1619,6 +1622,23 @@ M.setup = function(opts)
|
|||
end,
|
||||
})
|
||||
|
||||
if config.default_to_float then
|
||||
vim.api.nvim_create_autocmd('VimEnter', {
|
||||
desc = 'Open oil in a float when starting on a directory',
|
||||
group = aug,
|
||||
once = true,
|
||||
nested = true,
|
||||
callback = function()
|
||||
local util = require('oil.util')
|
||||
if util.is_oil_bufnr(0) then
|
||||
local url = vim.api.nvim_buf_get_name(0)
|
||||
vim.cmd.enew({ mods = { silent = true, noswapfile = true } })
|
||||
M.open_float(url)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if config.default_file_explorer then
|
||||
vim.api.nvim_create_autocmd('BufAdd', {
|
||||
desc = 'Detect directory buffer and open oil file browser',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue