neovim/lua/plugins/filetree.lua

94 lines
3.7 KiB
Lua

return {
{
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
"nvim-tree/nvim-web-devicons",
},
keys = {
{
"<leader>t",
function()
require("neo-tree.command").execute({
toggle = true,
source = "filesystem",
position = "left",
})
end,
desc = "Buffers (root dir)",
},
},
config = function()
-- automatically close file tree if file is selected
require("neo-tree").setup({
close_if_last_window = true,
event_handlers = {
{
event = "file_open_requested",
handler = function()
require("neo-tree.command").execute({ action = "close" })
end,
},
-- makes it so quitting inside buffer quits all buffers
{
event = "neo_tree_buffer_enter",
handler = function()
vim.cmd("cabbrev <buffer> q qall")
end,
},
},
-- filesystem = {
-- components = {
-- icon = function(config, node, state)
-- local icon = config.default or " "
-- local padding = config.padding or " "
-- local highlight = config.highlight or highlights.FILE_ICON
--
-- if node.type == "directory" then
-- highlight = highlights.DIRECTORY_ICON
-- if node:is_expanded() then
-- icon = config.folder_open or "-"
-- else
-- icon = config.folder_closed or "+"
-- end
-- elseif node.type == "file" then
-- local success, web_devicons = pcall(require, "nvim-web-devicons")
-- if success then
-- local devicon, hl = web_devicons.get_icon(node.name, node.ext)
-- icon = devicon or icon
-- highlight = hl or highlight
-- end
-- end
--
-- return {
-- text = icon .. padding,
-- highlight = highlight,
-- }
-- end,
-- }
-- }
})
-- auto open file tree on empty buffer or directory
vim.api.nvim_create_autocmd("VimEnter", {
callback = function(data)
local is_directory = vim.fn.isdirectory(data.file) == 1
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
if is_directory or no_name then
require("neo-tree.command").execute({
action = "focus",
source = "filesystem",
position = "left",
})
end
end,
})
end,
lazy = false, -- neo-tree lazy loads itself
}
}