nvimtree.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. item = "│",
  73. none = " ",
  74. },
  75. },
  76. icons = {
  77. webdev_colors = lvim.use_icons,
  78. show = {
  79. git = lvim.use_icons,
  80. folder = lvim.use_icons,
  81. file = lvim.use_icons,
  82. folder_arrow = lvim.use_icons,
  83. },
  84. glyphs = {
  85. default = "",
  86. symlink = "",
  87. git = {
  88. unstaged = "",
  89. staged = "S",
  90. unmerged = "",
  91. renamed = "➜",
  92. deleted = "",
  93. untracked = "U",
  94. ignored = "◌",
  95. },
  96. folder = {
  97. default = "",
  98. open = "",
  99. empty = "",
  100. empty_open = "",
  101. symlink = "",
  102. },
  103. },
  104. },
  105. highlight_git = true,
  106. root_folder_modifier = ":t",
  107. },
  108. filters = {
  109. dotfiles = false,
  110. custom = { "node_modules", "\\.cache" },
  111. exclude = {},
  112. },
  113. trash = {
  114. cmd = "trash",
  115. require_confirm = true,
  116. },
  117. log = {
  118. enable = false,
  119. truncate = false,
  120. types = {
  121. all = false,
  122. config = false,
  123. copy_paste = false,
  124. diagnostics = false,
  125. git = false,
  126. profile = false,
  127. },
  128. },
  129. actions = {
  130. use_system_clipboard = true,
  131. change_dir = {
  132. enable = true,
  133. global = false,
  134. restrict_above_cwd = false,
  135. },
  136. open_file = {
  137. quit_on_open = false,
  138. resize_window = false,
  139. window_picker = {
  140. enable = true,
  141. chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
  142. exclude = {
  143. filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" },
  144. buftype = { "nofile", "terminal", "help" },
  145. },
  146. },
  147. },
  148. },
  149. },
  150. }
  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. if lvim.builtin.nvimtree._setup_called then
  159. Log:debug "ignoring repeated setup call for nvim-tree, see kyazdani42/nvim-tree.lua#1308"
  160. return
  161. end
  162. lvim.builtin.which_key.mappings["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" }
  163. lvim.builtin.nvimtree._setup_called = true
  164. -- Implicitly update nvim-tree when project module is active
  165. if lvim.builtin.project.active then
  166. lvim.builtin.nvimtree.setup.respect_buf_cwd = true
  167. lvim.builtin.nvimtree.setup.update_cwd = true
  168. lvim.builtin.nvimtree.setup.update_focused_file = { enable = true, update_cwd = true }
  169. end
  170. local function telescope_find_files(_)
  171. require("lvim.core.nvimtree").start_telescope "find_files"
  172. end
  173. local function telescope_live_grep(_)
  174. require("lvim.core.nvimtree").start_telescope "live_grep"
  175. end
  176. -- Add useful keymaps
  177. if #lvim.builtin.nvimtree.setup.view.mappings.list == 0 then
  178. lvim.builtin.nvimtree.setup.view.mappings.list = {
  179. { key = { "l", "<CR>", "o" }, action = "edit", mode = "n" },
  180. { key = "h", action = "close_node" },
  181. { key = "v", action = "vsplit" },
  182. { key = "C", action = "cd" },
  183. { key = "gtf", action = "telescope_find_files", action_cb = telescope_find_files },
  184. { key = "gtg", action = "telescope_live_grep", action_cb = telescope_live_grep },
  185. }
  186. end
  187. nvim_tree.setup(lvim.builtin.nvimtree.setup)
  188. if lvim.builtin.nvimtree.on_config_done then
  189. lvim.builtin.nvimtree.on_config_done(nvim_tree)
  190. end
  191. end
  192. function M.start_telescope(telescope_mode)
  193. local node = require("nvim-tree.lib").get_node_at_cursor()
  194. local abspath = node.link_to or node.absolute_path
  195. local is_folder = node.open ~= nil
  196. local basedir = is_folder and abspath or vim.fn.fnamemodify(abspath, ":h")
  197. require("telescope.builtin")[telescope_mode] {
  198. cwd = basedir,
  199. }
  200. end
  201. return M