dotfiles/.config/nvim/lua/plugins/tree.lua

70 lines
1.5 KiB
Lua

local function on_attach(bufnr)
local api = require("nvim-tree.api")
local function opts(desc)
return { desc = "Tree: " .. desc, buffer = bufnr, noremap = true,
silent = true, nowait = true }
end
vim.keymap.set("n", "<CR>", api.node.open.edit, opts("Open"))
end
local tree = {
'nvim-tree/nvim-tree.lua',
lazy = false,
dependencies = { 'nvim-tree/nvim-web-devicons' },
opts = {
on_attach = on_attach,
disable_netrw = true,
sort_by = "case_sensitive",
view = {
adaptive_size = true,
centralize_selection = true,
number = true,
relativenumber = true,
},
renderer = {
group_empty = true,
highlight_git = true,
},
filters = {
dotfiles = true,
},
update_focused_file = {
enable = true,
},
actions = {
change_dir = {
enable = false,
},
},
},
}
local function is_modified_buffer_open(buffers)
for _, v in pairs(buffers) do
if v.name:match("NvimTree_") == nil then
return true
end
end
return false
end
-- [[
vim.api.nvim_create_autocmd("BufEnter", {
nested = true,
callback = function()
if
#vim.api.nvim_list_wins() == 1
and vim.api.nvim_buf_get_name(0):match("NvimTree_") ~= nil
and is_modified_buffer_open(vim.fn.getbufinfo({ bufmodified = 1 })) == false
then
vim.cmd("quit")
end
end,
})
-- ]]
return { tree }