nvim-tree.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. -- https://github.com/kyazdani42/nvim-tree.lua
  2. -- local nvim_tree = require'nvim-tree'
  3. local status, nvim_tree = pcall(require, "nvim-tree")
  4. if not status then
  5. vim.notify("没有找到 nvim-tree")
  6. return
  7. end
  8. -- 列表操作快捷键
  9. local function on_attach(bufnr)
  10. local api = require('nvim-tree.api')
  11. local function opts(desc)
  12. return {
  13. desc = 'nvim-tree: ' .. desc,
  14. buffer = bufnr,
  15. noremap = true,
  16. silent = true,
  17. nowait = true
  18. }
  19. end
  20. -- Default mappings not inserted as:
  21. -- remove_keymaps = true
  22. -- OR
  23. -- view.mappings.custom_only = true
  24. -- Mappings migrated from view.mappings.list
  25. --
  26. -- You will need to insert "your code goes here" for any mappings with a custom action_cb
  27. vim.keymap.set('n', 'o', api.node.open.edit, opts('Open'))
  28. vim.keymap.set('n', '<2-LeftMouse>', api.node.open.edit, opts('Open'))
  29. vim.keymap.set('n', '<CR>', api.node.run.system, opts('Run System'))
  30. vim.keymap.set('n', 'v', api.node.open.vertical, opts('Open: Vertical Split'))
  31. vim.keymap.set('n', 'h', api.node.open.horizontal, opts('Open: Horizontal Split'))
  32. vim.keymap.set('n', 'i', api.tree.toggle_gitignore_filter, opts('Toggle Git Ignore'))
  33. vim.keymap.set('n', '.', api.tree.toggle_hidden_filter, opts('Toggle Dotfiles'))
  34. vim.keymap.set('n', 'R', api.tree.reload, opts('Refresh'))
  35. vim.keymap.set('n', 'a', api.fs.create, opts('Create'))
  36. vim.keymap.set('n', 'd', api.fs.remove, opts('Delete'))
  37. vim.keymap.set('n', 'r', api.fs.rename, opts('Rename'))
  38. vim.keymap.set('n', 'x', api.fs.cut, opts('Cut'))
  39. vim.keymap.set('n', 'c', api.fs.copy.node, opts('Copy'))
  40. vim.keymap.set('n', 'p', api.fs.paste, opts('Paste'))
  41. vim.keymap.set('n', 'y', api.fs.copy.filename, opts('Copy Name'))
  42. vim.keymap.set('n', 'Y', api.fs.copy.relative_path, opts('Copy Relative Path'))
  43. vim.keymap.set('n', 'gy', api.fs.copy.absolute_path, opts('Copy Absolute Path'))
  44. vim.keymap.set('n', 'I', api.node.show_info_popup, opts('Info'))
  45. vim.keymap.set('n', 'n', api.node.open.tab, opts('Open: New Tab'))
  46. vim.keymap.set('n', ']', api.tree.change_root_to_node, opts('CD'))
  47. vim.keymap.set('n', '[', api.tree.change_root_to_parent, opts('Up'))
  48. end
  49. nvim_tree.setup({
  50. on_attach = on_attach,
  51. -- 完全禁止内置netrw
  52. disable_netrw = true,
  53. -- 不显示 git 状态图标
  54. git = {
  55. enable = false
  56. },
  57. -- project plugin 需要这样设置
  58. update_cwd = true,
  59. update_focused_file = {
  60. enable = true,
  61. update_cwd = true
  62. },
  63. filters = {
  64. -- 隐藏 .文件
  65. dotfiles = true
  66. -- 隐藏 node_modules 文件夹
  67. -- custom = { "node_modules" },
  68. },
  69. view = {
  70. -- 宽度
  71. width = 34,
  72. -- 也可以 'right'
  73. side = "left",
  74. -- 隐藏根目录
  75. hide_root_folder = false,
  76. -- 自定义列表中快捷键
  77. mappings = {
  78. -- 只用内置快捷键
  79. custom_only = true,
  80. list = list_keys
  81. },
  82. -- 不显示行数
  83. number = false,
  84. relativenumber = false,
  85. -- 显示图标
  86. signcolumn = "yes"
  87. },
  88. actions = {
  89. open_file = {
  90. -- 首次打开大小适配
  91. resize_window = true,
  92. -- 打开文件时关闭 tree
  93. quit_on_open = false
  94. }
  95. },
  96. -- wsl install -g wsl-open
  97. -- https://github.com/4U6U57/wsl-open/
  98. system_open = {
  99. -- mac
  100. cmd = "open"
  101. -- windows
  102. -- cmd = "wsl-open",
  103. }
  104. })