neovim/lua/plugins/file-tree.lua

48 lines
1.1 KiB
Lua
Raw Normal View History

2023-02-26 12:50:20 +00:00
-- disable netrw at the very start of your init.lua (strongly advised)
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- set termguicolors to enable highlight groups
vim.opt.termguicolors = true
-- OR setup with some options
require("nvim-tree").setup({
2023-02-26 13:29:03 +00:00
auto_reload_on_write = true,
sort_by = "case_sensitive",
sync_root_with_cwd = true,
respect_buf_cwd = true,
update_focused_file = {
enable = true,
update_root = true,
},
filters = { custom = { ".git" } },
view = {
width = 30,
mappings = {
list = {
{ key = "u", action = "dir_up" },
},
},
},
renderer = {
group_empty = true,
},
2023-02-26 12:50:20 +00:00
})
local function open_nvim_tree(data)
2023-02-26 13:29:03 +00:00
-- buffer is a directory
local directory = vim.fn.isdirectory(data.file) == 1
2023-02-26 12:50:20 +00:00
2023-02-26 13:29:03 +00:00
if not directory then
return
end
2023-02-26 12:50:20 +00:00
2023-02-26 13:29:03 +00:00
-- change to the directory
vim.cmd.cd(data.file)
2023-02-26 12:50:20 +00:00
2023-02-26 13:29:03 +00:00
-- open the tree
require("nvim-tree.api").tree.open()
2023-02-26 12:50:20 +00:00
end
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })