1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
local group = vim.api.nvim_create_augroup("PrismiteNvim", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
group = group,
callback = function()
if require("nvim-tree.utils").is_nvim_tree_buf() then
vim.cmd "stopinsert"
end
end,
})
-- By https://github.com/marvinth01, taken from https://github.com/nvim-tree/nvim-tree.lua/wiki/Auto-Close#marvinth01
vim.api.nvim_create_autocmd("QuitPre", {
group = group,
callback = function()
local tree_wins = {}
local floating_wins = {}
local wins = vim.api.nvim_list_wins()
for _, w in ipairs(wins) do
local bufname = vim.api.nvim_buf_get_name(vim.api.nvim_win_get_buf(w))
if bufname:match "NvimTree_" ~= nil then
table.insert(tree_wins, w)
end
if vim.api.nvim_win_get_config(w).relative ~= "" then
table.insert(floating_wins, w)
end
end
if 1 == #wins - #floating_wins - #tree_wins then
-- Should quit, so we close all invalid windows.
for _, w in ipairs(tree_wins) do
vim.api.nvim_win_close(w, true)
end
end
end,
})
|