-- Neovim plugin to manage the file system and other tree like structures. -- https://github.com/nvim-neo-tree/neo-tree.nvim -- vim.api.nvim_create_autocmd("VimEnter", { desc = "Loads neo-tree when opening nvim with a directory", callback = function(data) -- If nvim was started with a directory local directory = vim.fn.isdirectory(data.file) == 1 if directory then vim.cmd("Neotree reveal") end end, }) -- vim.api.nvim_create_autocmd("BufEnter", { -- group = vim.api.nvim_create_augroup("load_neo_tree", {}), -- desc = "Loads neo-tree when opening a buffer", -- callback = function() -- -- Only run if Neo-tree is open -- if vim.fn.exists("#neo-tree#") == 1 then -- pcall(function() -- vim.cmd("Neotree reveal") -- end) -- end -- end, -- }) return { "neo-tree.nvim", cmd = { "Neotree" }, after = function() require("neo-tree").setup({ add_blank_line_at_top = false, auto_clean_after_session_restore = false, sort_case_insensitive = true, sort_function = function(a, b) -- Explanation: sort only using the path, not the type, -- but put a prefix path after if it's a directory if string.find(a.path, b.path, 1, true) == 1 and b.type == "directory" and a.path ~= b.path then return true elseif string.find(b.path, a.path, 1, true) == 1 and a.type == "directory" and a.path ~= b.path then return false else return a.path:lower() < b.path:lower() end end, buffers = { follow_current_file = { enabled = true, leave_dirs_open = true }, group_empty_dirs = false, show_unloaded = true, }, -- https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/FAQ#bdelete-makes-the-tree-spans-the-whole-window-how-do-i-prevent-it close_if_last_window = false, default_source = "buffers", enable_cursor_hijack = true, enable_diagnostics = true, enable_git_status = true, enable_modified_markers = true, enable_opened_markers = true, enable_refresh_on_write = true, sources = { "buffers", "filesystem", --"git_status", -- "document_symbols", }, filesystem = { filtered_items = { visible = true }, group_empty_dirs = false, hijack_netrw_behavior = "open_default", use_libuv_file_watcher = true, }, git_status_async = true, hide_root_node = false, log_level = "info", log_to_file = false, open_files_do_not_replace_types = { "terminal", "Trouble", "qf", "edgy" }, open_files_in_last_window = true, retain_hidden_root_indent = false, signs = true, window = { position = "right", mappings = { -- ["i"] = "move_cursor_up", ["I"] = function(state) local tree = state.tree local node = tree:get_node() local siblings = tree:get_nodes(node:get_parent_id()) local renderer = require("neo-tree.ui.renderer") renderer.focus_node(state, siblings[1]:get_id()) end, ["K"] = function(state) local tree = state.tree local node = tree:get_node() local siblings = tree:get_nodes(node:get_parent_id()) local renderer = require("neo-tree.ui.renderer") renderer.focus_node(state, siblings[#siblings]:get_id()) end, }, }, }) end, }