navigation: make sure to quit vim if oil is the only open buffer
This commit is contained in:
@@ -118,6 +118,12 @@ Tasks integrate with quickfix: errors populate the quickfix list.
|
||||
|
||||
Auto-installed servers: `gopls`, `bashls`, `ansiblels`, `yamlls`.
|
||||
|
||||
## Plugins
|
||||
|
||||
| Command | Action |
|
||||
|---------|--------|
|
||||
| `:lua vim.pack.update()` | Update all plugins |
|
||||
|
||||
## Treesitter
|
||||
|
||||
| Command | Action |
|
||||
|
||||
@@ -6,6 +6,35 @@ vim.api.nvim_create_autocmd("TextYankPost", {
|
||||
end,
|
||||
})
|
||||
|
||||
-- Quit Neovim if only oil windows remain (skip during startup)
|
||||
_G._nvim_ready = false
|
||||
vim.api.nvim_create_autocmd("VimEnter", {
|
||||
group = vim.api.nvim_create_augroup("nvim_ready_flag", { clear = true }),
|
||||
callback = function()
|
||||
vim.schedule(function() _G._nvim_ready = true end)
|
||||
end,
|
||||
})
|
||||
|
||||
function _G.quit_if_only_oil()
|
||||
vim.schedule(function()
|
||||
if not _G._nvim_ready then return end
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
if vim.api.nvim_win_get_config(win).relative == "" then
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
local ft = vim.bo[buf].filetype
|
||||
local name = vim.api.nvim_buf_get_name(buf)
|
||||
if ft ~= "oil" and name ~= "" then
|
||||
return
|
||||
end
|
||||
if ft ~= "oil" and name == "" and vim.bo[buf].modified then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
vim.cmd("qa")
|
||||
end)
|
||||
end
|
||||
|
||||
-- Buffer tab navigation (per-window, exclusive)
|
||||
local function cycle_buf(dir)
|
||||
local bufs = _G.get_win_bufs()
|
||||
@@ -38,9 +67,16 @@ vim.keymap.set("n", "<leader>x", function()
|
||||
vim.bo.bufhidden = "wipe"
|
||||
end
|
||||
vim.cmd("bdelete " .. current)
|
||||
_G.quit_if_only_oil()
|
||||
end, { desc = "Close buffer tab" })
|
||||
|
||||
|
||||
-- Also check when a window is closed (e.g. :q)
|
||||
vim.api.nvim_create_autocmd("WinClosed", {
|
||||
group = vim.api.nvim_create_augroup("quit_if_only_oil_winclose", { clear = true }),
|
||||
callback = function() _G.quit_if_only_oil() end,
|
||||
})
|
||||
|
||||
-- Prevent splitting from oil — redirect to last code window
|
||||
vim.api.nvim_create_autocmd("WinNew", {
|
||||
group = vim.api.nvim_create_augroup("no_split_oil", { clear = true }),
|
||||
|
||||
@@ -3,7 +3,7 @@ vim.pack.add({
|
||||
"https://github.com/nvim-treesitter/nvim-treesitter",
|
||||
"https://github.com/williamboman/mason.nvim",
|
||||
"https://github.com/williamboman/mason-lspconfig.nvim",
|
||||
{ src = "https://github.com/saghen/blink.cmp", version = vim.version.range("1.*") },
|
||||
{ src = "https://github.com/saghen/blink.cmp", version = vim.version.range("1.*"), build = "cargo build --release" },
|
||||
"https://github.com/stevearc/oil.nvim",
|
||||
"https://github.com/stevearc/overseer.nvim",
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"plugins": {
|
||||
"blink.cmp": {
|
||||
"rev": "e9556f9b981f395e22a6bfd69fd5f3008a2a6cd9",
|
||||
"rev": "451168851e8e2466bc97ee3e026c3dcb9141ce07",
|
||||
"src": "https://github.com/saghen/blink.cmp",
|
||||
"version": "1.0.0 - 2.0.0"
|
||||
},
|
||||
@@ -10,7 +10,7 @@
|
||||
"src": "https://github.com/rebelot/kanagawa.nvim"
|
||||
},
|
||||
"mason-lspconfig.nvim": {
|
||||
"rev": "a324581a3c83fdacdb9804b79de1cbe00ce18550",
|
||||
"rev": "a676ab7282da8d651e175118bcf54483ca11e46d",
|
||||
"src": "https://github.com/williamboman/mason-lspconfig.nvim"
|
||||
},
|
||||
"mason.nvim": {
|
||||
@@ -18,11 +18,11 @@
|
||||
"src": "https://github.com/williamboman/mason.nvim"
|
||||
},
|
||||
"nvim-lspconfig": {
|
||||
"rev": "2b87d107942b9eebef768512f5849330335a9493",
|
||||
"rev": "dc2f86d2b66a6e01a98c37cdadd3be3e90f8ab9a",
|
||||
"src": "https://github.com/neovim/nvim-lspconfig"
|
||||
},
|
||||
"nvim-treesitter": {
|
||||
"rev": "1970f0d3bbb99c7659e58914948749437c7b7398",
|
||||
"rev": "2cc172c28e5550e00e6beead4599b1469469c1c7",
|
||||
"src": "https://github.com/nvim-treesitter/nvim-treesitter"
|
||||
},
|
||||
"oil.nvim": {
|
||||
@@ -30,7 +30,7 @@
|
||||
"src": "https://github.com/stevearc/oil.nvim"
|
||||
},
|
||||
"overseer.nvim": {
|
||||
"rev": "2802c15182dae2de71f9c82e918d7ba850b90c22",
|
||||
"rev": "a2194447f4c5a1baf95139c5c7b539fa7b0d012f",
|
||||
"src": "https://github.com/stevearc/overseer.nvim"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user