1 -- Neovim plugin to manage the file system and other tree like structures.
2 -- https://github.com/nvim-neo-tree/neo-tree.nvim
4 vim.api.nvim_create_autocmd("VimEnter", {
5 desc = "Loads neo-tree when opening nvim with a directory",
6 callback = function(data)
7 -- If nvim was started with a directory
8 local directory = vim.fn.isdirectory(data.file) == 1
10 vim.cmd("Neotree reveal")
15 -- vim.api.nvim_create_autocmd("BufEnter", {
16 -- group = vim.api.nvim_create_augroup("load_neo_tree", {}),
17 -- desc = "Loads neo-tree when opening a buffer",
18 -- callback = function()
19 -- -- Only run if Neo-tree is open
20 -- if vim.fn.exists("#neo-tree#") == 1 then
22 -- vim.cmd("Neotree reveal")
32 require("neo-tree").setup({
33 add_blank_line_at_top = false,
34 auto_clean_after_session_restore = false,
35 sort_case_insensitive = true,
36 sort_function = function(a, b)
37 -- Explanation: sort only using the path, not the type,
38 -- but put a prefix path after if it's a directory
39 if string.find(a.path, b.path, 1, true) == 1 and b.type == "directory" and a.path ~= b.path then
41 elseif string.find(b.path, a.path, 1, true) == 1 and a.type == "directory" and a.path ~= b.path then
44 return a.path:lower() < b.path:lower()
48 follow_current_file = { enabled = true, leave_dirs_open = true },
49 group_empty_dirs = false,
52 -- https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/FAQ#bdelete-makes-the-tree-spans-the-whole-window-how-do-i-prevent-it
53 close_if_last_window = false,
54 default_source = "buffers",
55 enable_cursor_hijack = true,
56 enable_diagnostics = true,
57 enable_git_status = true,
58 enable_modified_markers = true,
59 enable_opened_markers = true,
60 enable_refresh_on_write = true,
65 -- "document_symbols",
68 filtered_items = { visible = true },
69 group_empty_dirs = false,
70 hijack_netrw_behavior = "open_default",
71 use_libuv_file_watcher = true,
73 git_status_async = true,
74 hide_root_node = false,
77 open_files_do_not_replace_types = { "terminal", "Trouble", "qf", "edgy" },
78 open_files_in_last_window = true,
79 retain_hidden_root_indent = false,
84 -- ["i"] = "move_cursor_up",
85 ["I"] = function(state)
86 local tree = state.tree
87 local node = tree:get_node()
88 local siblings = tree:get_nodes(node:get_parent_id())
89 local renderer = require("neo-tree.ui.renderer")
90 renderer.focus_node(state, siblings[1]:get_id())
92 ["K"] = function(state)
93 local tree = state.tree
94 local node = tree:get_node()
95 local siblings = tree:get_nodes(node:get_parent_id())
96 local renderer = require("neo-tree.ui.renderer")
97 renderer.focus_node(state, siblings[#siblings]:get_id())