Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto-quit vim if oil is closed as last buffer #491

Merged
merged 8 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ require("oil").setup({
constrain_cursor = "editable",
-- Set to true to watch the filesystem for changes and reload oil
watch_for_changes = false,
-- Automatically quit vim if Oil is closed and no other buffers are open
auto_close_last_buffer = false,
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
-- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" })
-- Additionally, if it is a string that matches "actions.<name>",
Expand Down
2 changes: 2 additions & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ local default_config = {
constrain_cursor = "editable",
-- Set to true to watch the filesystem for changes and reload oil
watch_for_changes = false,
-- Automatically quit vim if Oil is closed and no other buffers are open
auto_close_last_buffer = false,
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
-- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" })
-- Additionally, if it is a string that matches "actions.<name>",
Expand Down
10 changes: 8 additions & 2 deletions lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,14 @@ M.close = function()
local oilbuf = vim.api.nvim_get_current_buf()
ok = pcall(vim.cmd.bprev)
if not ok then
-- If `bprev` failed, there are no buffers open so we should create a new one with enew
vim.cmd.enew()
local config = require("oil.config")
-- If `bprev` failed, there are no buffers open. then,
if config.auto_close_last_buffer then
vim.cmd("quit")
else
-- we should create a new one with enew
vim.cmd.enew()
end
end
vim.api.nvim_buf_delete(oilbuf, { force = true })
end
Expand Down
Loading