nvimtree.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. local M = {}
  2. local Log = require "lvim.core.log"
  3. function M.config()
  4. lvim.builtin.nvimtree = {
  5. active = true,
  6. on_config_done = nil,
  7. setup = {
  8. disable_netrw = true,
  9. hijack_netrw = true,
  10. open_on_setup = false,
  11. open_on_setup_file = false,
  12. sort_by = "name",
  13. ignore_buffer_on_setup = false,
  14. ignore_ft_on_setup = {
  15. "startify",
  16. "dashboard",
  17. "alpha",
  18. },
  19. auto_reload_on_write = true,
  20. hijack_unnamed_buffer_when_opening = false,
  21. hijack_directories = {
  22. enable = true,
  23. auto_open = true,
  24. },
  25. open_on_tab = false,
  26. hijack_cursor = false,
  27. update_cwd = false,
  28. diagnostics = {
  29. enable = lvim.use_icons,
  30. show_on_dirs = false,
  31. icons = {
  32. hint = "",
  33. info = "",
  34. warning = "",
  35. error = "",
  36. },
  37. },
  38. update_focused_file = {
  39. enable = true,
  40. update_cwd = true,
  41. ignore_list = {},
  42. },
  43. system_open = {
  44. cmd = nil,
  45. args = {},
  46. },
  47. git = {
  48. enable = true,
  49. ignore = false,
  50. timeout = 200,
  51. },
  52. view = {
  53. width = 30,
  54. height = 30,
  55. hide_root_folder = false,
  56. side = "left",
  57. preserve_window_proportions = false,
  58. mappings = {
  59. custom_only = false,
  60. list = {},
  61. },
  62. number = false,
  63. relativenumber = false,
  64. signcolumn = "yes",
  65. },
  66. renderer = {
  67. indent_markers = {
  68. enable = false,
  69. icons = {
  70. corner = "└ ",
  71. edge = "│ ",
  72. none = " ",
  73. },
  74. },
  75. icons = {
  76. webdev_colors = lvim.use_icons,
  77. show = {
  78. git = lvim.use_icons,
  79. folder = lvim.use_icons,
  80. file = lvim.use_icons,
  81. folder_arrow = lvim.use_icons,
  82. },
  83. glyphs = {
  84. default = "",
  85. symlink = "",
  86. git = {
  87. unstaged = "",
  88. staged = "S",
  89. unmerged = "",
  90. renamed = "➜",
  91. deleted = "",
  92. untracked = "U",
  93. ignored = "◌",
  94. },
  95. folder = {
  96. default = "",
  97. open = "",
  98. empty = "",
  99. empty_open = "",
  100. symlink = "",
  101. },
  102. },
  103. },
  104. highlight_git = true,
  105. root_folder_modifier = ":t",
  106. },
  107. filters = {
  108. dotfiles = false,
  109. custom = { "node_modules", "\\.cache" },
  110. exclude = {},
  111. },
  112. trash = {
  113. cmd = "trash",
  114. require_confirm = true,
  115. },
  116. log = {
  117. enable = false,
  118. truncate = false,
  119. types = {
  120. all = false,
  121. config = false,
  122. copy_paste = false,
  123. diagnostics = false,
  124. git = false,
  125. profile = false,
  126. },
  127. },
  128. actions = {
  129. use_system_clipboard = true,
  130. change_dir = {
  131. enable = true,
  132. global = false,
  133. restrict_above_cwd = false,
  134. },
  135. open_file = {
  136. quit_on_open = false,
  137. resize_window = false,
  138. window_picker = {
  139. enable = true,
  140. chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
  141. exclude = {
  142. filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" },
  143. buftype = { "nofile", "terminal", "help" },
  144. },
  145. },
  146. },
  147. },
  148. },
  149. }
  150. lvim.builtin.which_key.mappings["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" }
  151. end
  152. function M.setup()
  153. local status_ok, nvim_tree = pcall(require, "nvim-tree")
  154. if not status_ok then
  155. Log:error "Failed to load nvim-tree"
  156. return
  157. end
  158. for opt, val in pairs(lvim.builtin.nvimtree) do
  159. vim.g["nvim_tree_" .. opt] = val
  160. end
  161. -- Implicitly update nvim-tree when project module is active
  162. if lvim.builtin.project.active then
  163. lvim.builtin.nvimtree.setup.respect_buf_cwd = true
  164. lvim.builtin.nvimtree.setup.update_cwd = true
  165. lvim.builtin.nvimtree.setup.update_focused_file = { enable = true, update_cwd = true }
  166. end
  167. local function telescope_find_files(_)
  168. require("lvim.core.nvimtree").start_telescope "find_files"
  169. end
  170. local function telescope_live_grep(_)
  171. require("lvim.core.nvimtree").start_telescope "live_grep"
  172. end
  173. -- Add useful keymaps
  174. if #lvim.builtin.nvimtree.setup.view.mappings.list == 0 then
  175. lvim.builtin.nvimtree.setup.view.mappings.list = {
  176. { key = { "l", "<CR>", "o" }, action = "edit", mode = "n" },
  177. { key = "h", action = "close_node" },
  178. { key = "v", action = "vsplit" },
  179. { key = "C", action = "cd" },
  180. { key = "gtf", action = "telescope_find_files", action_cb = telescope_find_files },
  181. { key = "gtg", action = "telescope_live_grep", action_cb = telescope_live_grep },
  182. }
  183. end
  184. nvim_tree.setup(lvim.builtin.nvimtree.setup)
  185. if lvim.builtin.nvimtree.on_config_done then
  186. lvim.builtin.nvimtree.on_config_done(nvim_tree)
  187. end
  188. end
  189. function M.start_telescope(telescope_mode)
  190. local node = require("nvim-tree.lib").get_node_at_cursor()
  191. local abspath = node.link_to or node.absolute_path
  192. local is_folder = node.open ~= nil
  193. local basedir = is_folder and abspath or vim.fn.fnamemodify(abspath, ":h")
  194. require("telescope.builtin")[telescope_mode] {
  195. cwd = basedir,
  196. }
  197. end
  198. return M