From 3fede7d809f3e999c7b4d463f445a2a0a4cee5a2 Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Wed, 18 Mar 2026 14:12:55 -0400 Subject: [PATCH] feat(config): add `default_to_float` option (#173) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- doc/oil.txt | 10 ++++++++++ doc/upstream.md | 2 +- lua/oil/config.lua | 3 +++ lua/oil/init.lua | 20 ++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/doc/oil.txt b/doc/oil.txt index b0807df..8f93f40 100644 --- a/doc/oil.txt +++ b/doc/oil.txt @@ -61,6 +61,9 @@ The full list of options with their defaults: -- Oil will take over directory buffers (e.g. `vim .` or `:e src/`) -- Set to false if you want some other plugin (e.g. netrw) to open when you edit directories. default_file_explorer = true, + -- When true, oil always opens in a floating window. Applies to :Oil, all open() calls, + -- and directory buffers opened on startup (e.g. `nvim .`). + default_to_float = false, -- Id is automatically added at the beginning, and name at the end -- See :help oil-columns columns = { @@ -293,6 +296,13 @@ The full list of options with their defaults: OPTIONS *oil-options* +default_to_float *oil.default_to_float* + type: `boolean` default: `false` + When `true`, oil always opens in a floating window. Applies to all + `open()` calls (`:Oil`, default keymaps) and to directory buffers opened + on startup (e.g. `nvim .`). Individual calls to `open_float()` or + `open()` still work regardless of this setting. + skip_confirm_for_simple_edits *oil.skip_confirm_for_simple_edits* type: `boolean` default: `false` Before performing filesystem operations, Oil displays a confirmation popup to ensure diff --git a/doc/upstream.md b/doc/upstream.md index 17f4953..9c9a765 100644 --- a/doc/upstream.md +++ b/doc/upstream.md @@ -51,7 +51,7 @@ issues against this fork. | [#288](https://github.com/stevearc/oil.nvim/issues/288) | Oil failing to load | not actionable — no reliable repro, likely lazy.nvim timing | | [#289](https://github.com/stevearc/oil.nvim/issues/289) | Show absolute path toggle | not actionable — display solved by `get_win_title`, editing consolidated into [#32](https://github.com/barrettruth/canola.nvim/issues/32) | | [#294](https://github.com/stevearc/oil.nvim/issues/294) | Can't handle emojis in filenames | not actionable — libuv bug ([nodejs/node#49042](https://github.com/nodejs/node/issues/49042)) | -| [#298](https://github.com/stevearc/oil.nvim/issues/298) | Open float on neovim directory startup | open | +| [#298](https://github.com/stevearc/oil.nvim/issues/298) | Open float on neovim directory startup | fixed ([#173](https://github.com/barrettruth/canola.nvim/pull/173)) | | [#302](https://github.com/stevearc/oil.nvim/issues/302) | `buflisted=true` after jumplist nav | fixed ([#71](https://github.com/barrettruth/canola.nvim/pull/71)) | | [#303](https://github.com/stevearc/oil.nvim/issues/303) | Preview in float window mode | fixed — upstream [#403](https://github.com/stevearc/oil.nvim/pull/403), `config.float.preview_split` | | [#325](https://github.com/stevearc/oil.nvim/issues/325) | oil-ssh error from command line | fixed | diff --git a/lua/oil/config.lua b/lua/oil/config.lua index 1d556cd..be16f01 100644 --- a/lua/oil/config.lua +++ b/lua/oil/config.lua @@ -2,6 +2,7 @@ local default_config = { -- Oil will take over directory buffers (e.g. `vim .` or `:e src/`) -- Set to false if you want some other plugin (e.g. netrw) to open when you edit directories. default_file_explorer = true, + default_to_float = false, -- Id is automatically added at the beginning, and name at the end -- See :help oil-columns columns = { @@ -250,6 +251,7 @@ default_config.view_options.highlight_filename = nil ---@field adapter_aliases table Hidden from SetupOpts ---@field silence_scp_warning? boolean Undocumented option ---@field default_file_explorer boolean +---@field default_to_float boolean ---@field columns oil.ColumnSpec[] ---@field buf_options table ---@field win_options table @@ -288,6 +290,7 @@ local M = {} ---@class (exact) oil.SetupOpts ---@field default_file_explorer? boolean Oil will take over directory buffers (e.g. `vim .` or `:e src/`). Set to false if you still want to use netrw. +---@field default_to_float? boolean When true, oil always opens in a floating window ---@field columns? oil.ColumnSpec[] The columns to display. See :help oil-columns. ---@field buf_options? table Buffer-local options to use for oil buffers ---@field win_options? table Window-local options to use for oil buffers diff --git a/lua/oil/init.lua b/lua/oil/init.lua index f71f52e..dbf5296 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -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',