nvimtree.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. ignore_buffer_on_setup = false,
  12. ignore_ft_on_setup = {
  13. "startify",
  14. "dashboard",
  15. "alpha",
  16. },
  17. auto_reload_on_write = true,
  18. hijack_unnamed_buffer_when_opening = false,
  19. hijack_directories = {
  20. enable = true,
  21. auto_open = true,
  22. },
  23. update_to_buf_dir = {
  24. enable = true,
  25. auto_open = true,
  26. },
  27. auto_close = false,
  28. open_on_tab = false,
  29. hijack_cursor = false,
  30. update_cwd = false,
  31. diagnostics = {
  32. enable = true,
  33. icons = {
  34. hint = "",
  35. info = "",
  36. warning = "",
  37. error = "",
  38. },
  39. },
  40. update_focused_file = {
  41. enable = true,
  42. update_cwd = true,
  43. ignore_list = {},
  44. },
  45. system_open = {
  46. cmd = nil,
  47. args = {},
  48. },
  49. git = {
  50. enable = true,
  51. ignore = false,
  52. timeout = 200,
  53. },
  54. view = {
  55. width = 30,
  56. height = 30,
  57. hide_root_folder = false,
  58. side = "left",
  59. auto_resize = false,
  60. mappings = {
  61. custom_only = false,
  62. list = {},
  63. },
  64. number = false,
  65. relativenumber = false,
  66. signcolumn = "yes",
  67. },
  68. filters = {
  69. dotfiles = false,
  70. custom = { "node_modules", ".cache" },
  71. },
  72. trash = {
  73. cmd = "trash",
  74. require_confirm = true,
  75. },
  76. actions = {
  77. change_dir = {
  78. global = false,
  79. },
  80. open_file = {
  81. quit_on_open = false,
  82. },
  83. window_picker = {
  84. enable = false,
  85. chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
  86. exclude = {},
  87. },
  88. },
  89. },
  90. show_icons = {
  91. git = 1,
  92. folders = 1,
  93. files = 1,
  94. folder_arrows = 1,
  95. },
  96. git_hl = 1,
  97. root_folder_modifier = ":t",
  98. icons = {
  99. default = "",
  100. symlink = "",
  101. git = {
  102. unstaged = "",
  103. staged = "S",
  104. unmerged = "",
  105. renamed = "➜",
  106. deleted = "",
  107. untracked = "U",
  108. ignored = "◌",
  109. },
  110. folder = {
  111. default = "",
  112. open = "",
  113. empty = "",
  114. empty_open = "",
  115. symlink = "",
  116. },
  117. },
  118. }
  119. lvim.builtin.which_key.mappings["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" }
  120. end
  121. function M.setup()
  122. local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config")
  123. if not status_ok then
  124. Log:error "Failed to load nvim-tree.config"
  125. return
  126. end
  127. for opt, val in pairs(lvim.builtin.nvimtree) do
  128. vim.g["nvim_tree_" .. opt] = val
  129. end
  130. -- Implicitly update nvim-tree when project module is active
  131. if lvim.builtin.project.active then
  132. lvim.builtin.nvimtree.respect_buf_cwd = 1
  133. lvim.builtin.nvimtree.setup.update_cwd = true
  134. lvim.builtin.nvimtree.setup.update_focused_file = { enable = true, update_cwd = true }
  135. end
  136. local function telescope_find_files(_)
  137. require("lvim.core.nvimtree").start_telescope "find_files"
  138. end
  139. local function telescope_live_grep(_)
  140. require("lvim.core.nvimtree").start_telescope "live_grep"
  141. end
  142. -- Add useful keymaps
  143. if #lvim.builtin.nvimtree.setup.view.mappings.list == 0 then
  144. lvim.builtin.nvimtree.setup.view.mappings.list = {
  145. { key = { "l", "<CR>", "o" }, action = "edit", mode = "n" },
  146. { key = "h", action = "close_node" },
  147. { key = "v", action = "vsplit" },
  148. { key = "C", action = "cd" },
  149. { key = "gtf", action = "telescope_find_files", action_cb = telescope_find_files },
  150. { key = "gtg", action = "telescope_live_grep", action_cb = telescope_live_grep },
  151. }
  152. end
  153. if lvim.builtin.nvimtree.on_config_done then
  154. lvim.builtin.nvimtree.on_config_done(nvim_tree_config)
  155. end
  156. require("nvim-tree").setup(lvim.builtin.nvimtree.setup)
  157. end
  158. function M.start_telescope(telescope_mode)
  159. local node = require("nvim-tree.lib").get_node_at_cursor()
  160. local abspath = node.link_to or node.absolute_path
  161. local is_folder = node.open ~= nil
  162. local basedir = is_folder and abspath or vim.fn.fnamemodify(abspath, ":h")
  163. require("telescope.builtin")[telescope_mode] {
  164. cwd = basedir,
  165. }
  166. end
  167. return M