]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/nvim/lua/plugins/neo-tree.lua
+use/op(nvim): tweak config
[julm/julm-nix.git] / home-manager / profiles / nvim / lua / plugins / neo-tree.lua
1 -- Neovim plugin to manage the file system and other tree like structures.
2 -- https://github.com/nvim-neo-tree/neo-tree.nvim
3 --
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
9 if directory then
10 vim.cmd("Neotree reveal")
11 end
12 end,
13 })
14
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
21 -- pcall(function()
22 -- vim.cmd("Neotree reveal")
23 -- end)
24 -- end
25 -- end,
26 -- })
27
28 return {
29 "neo-tree.nvim",
30 cmd = { "Neotree" },
31 after = function()
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
40 return true
41 elseif string.find(b.path, a.path, 1, true) == 1 and a.type == "directory" and a.path ~= b.path then
42 return false
43 else
44 return a.path:lower() < b.path:lower()
45 end
46 end,
47 buffers = {
48 follow_current_file = { enabled = true, leave_dirs_open = true },
49 group_empty_dirs = false,
50 show_unloaded = true,
51 },
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,
61 sources = {
62 "buffers",
63 "filesystem",
64 --"git_status",
65 -- "document_symbols",
66 },
67 filesystem = {
68 filtered_items = { visible = true },
69 group_empty_dirs = false,
70 hijack_netrw_behavior = "open_default",
71 use_libuv_file_watcher = true,
72 },
73 git_status_async = true,
74 hide_root_node = false,
75 log_level = "info",
76 log_to_file = 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,
80 signs = true,
81 window = {
82 position = "right",
83 mappings = {
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())
91 end,
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())
98 end,
99 },
100 },
101 })
102 end,
103 }