nvimtree.lua 5.3 KB

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