@@ -3,22 +3,151 @@ return {
33 version = ' *' ,
44 dependencies = {
55 ' nvim-lua/plenary.nvim' ,
6- ' nvim-tree/nvim-web-devicons' , -- not strictly required, but recommended
6+ ' nvim-tree/nvim-web-devicons' ,
77 ' MunifTanjim/nui.nvim' ,
8+ ' saifulapm/neotree-file-nesting-config' ,
89 },
910 cmd = ' Neotree' ,
11+ opts = {
12+ -- recommended config for better UI
13+ hide_root_node = true ,
14+ retain_hidden_root_indent = true ,
15+ filesystem = {
16+ filtered_items = {
17+ show_hidden_count = false ,
18+ never_show = {
19+ ' .DS_Store' ,
20+ },
21+ },
22+ },
23+ default_component_configs = {
24+ indent = {
25+ with_expanders = true ,
26+ expander_collapsed = ' ' ,
27+ expander_expanded = ' ' ,
28+ },
29+ },
30+ },
1031 keys = {
1132 { ' \\ ' , ' :Neotree reveal<CR>' , desc = ' NeoTree reveal' , silent = true },
33+ {
34+ ' <leader>b' ,
35+ function ()
36+ require (' neo-tree.command' ).execute { toggle = true , source = ' buffers' , position = ' left' }
37+ end ,
38+ desc = ' Buffers (root dir)' ,
39+ },
40+ {
41+ ' <leader>e' ,
42+ function ()
43+ require (' neo-tree.command' ).execute { toggle = true , source = ' filesystem' , position = ' left' }
44+ end ,
45+ desc = ' Filesystem (root dir)' ,
46+ },
47+ {
48+ ' <leader>g' ,
49+ function ()
50+ require (' neo-tree.command' ).execute { toggle = true , source = ' git_status' , position = ' left' }
51+ end ,
52+ desc = ' Filesystem (root dir)' ,
53+ },
1254 },
13- opts = {
14- filesystem = {
55+ config = function (_ , opts )
56+ opts .nesting_rules = require (' neotree-file-nesting-config' ).nesting_rules
57+ require (' neo-tree' ).setup (opts )
58+
59+ local inputs = require ' neo-tree.ui.inputs'
60+ -- Trash the target
61+ local function trash (state )
62+ local node = state .tree :get_node ()
63+ if node .type == ' message' then
64+ return
65+ end
66+ local _ , name = require (' neo-tree.utils' ).split_path (node .path )
67+ local msg = string.format (" Are you sure you want to trash '%s'?" , name )
68+ inputs .confirm (msg , function (confirmed )
69+ if not confirmed then
70+ return
71+ end
72+ vim .api .nvim_command (' silent !trash -F ' .. node .path )
73+ require (' neo-tree.sources.manager' ).refresh (state )
74+ end )
75+ end
76+
77+ -- Trash the selections (visual mode)
78+ local function trash_visual (state , selected_nodes )
79+ local paths_to_trash = {}
80+ for _ , node in ipairs (selected_nodes ) do
81+ if node .type ~= ' message' then
82+ table.insert (paths_to_trash , node .path )
83+ end
84+ end
85+ local msg = ' Are you sure you want to trash ' .. # paths_to_trash .. ' items?'
86+ inputs .confirm (msg , function (confirmed )
87+ if not confirmed then
88+ return
89+ end
90+ for _ , path in ipairs (paths_to_trash ) do
91+ vim .api .nvim_command (' silent !trash -F ' .. path )
92+ end
93+ require (' neo-tree.sources.manager' ).refresh (state )
94+ end )
95+ end
96+
97+ require (' neo-tree' ).setup {
98+ event_handlers = {
99+ {
100+ event = ' neo_tree_buffer_enter' ,
101+ handler = function ()
102+ vim .cmd ' highlight! Cursor blend=100'
103+ end ,
104+ },
105+ {
106+ event = ' neo_tree_buffer_leave' ,
107+ handler = function ()
108+ vim .cmd ' highlight! Cursor guibg=#5f87af blend=0'
109+ end ,
110+ },
111+ },
15112 window = {
16113 mappings = {
17- [' \\ ' ] = ' close_window' ,
18- [' <space>' ] = { ' toggle_node' , nowait = true },
19- [' P' ] = { ' toggle_preview' , config = { use_float = false } },
114+ [' T' ] = ' trash' ,
115+ [' h' ] = function (state )
116+ local node = state .tree :get_node ()
117+ if node .type == ' directory' and node :is_expanded () then
118+ require (' neo-tree.sources.filesystem' ).toggle_directory (state , node )
119+ else
120+ require (' neo-tree.ui.renderer' ).focus_node (state , node :get_parent_id ())
121+ end
122+ end ,
123+ [' l' ] = function (state )
124+ local node = state .tree :get_node ()
125+ if node .type == ' directory' then
126+ if not node :is_expanded () then
127+ require (' neo-tree.sources.filesystem' ).toggle_directory (state , node )
128+ elseif node :has_children () then
129+ require (' neo-tree.ui.renderer' ).focus_node (state , node :get_child_ids ()[1 ])
130+ end
131+ else
132+ state .commands [' open' ](state )
133+ vim .cmd ' Neotree reveal'
134+ end
135+ end ,
136+ [' <tab>' ] = function (state )
137+ local node = state .tree :get_node ()
138+ if require (' neo-tree.utils' ).is_expandable (node ) then
139+ state .commands [' toggle_node' ](state )
140+ else
141+ state .commands [' open' ](state )
142+ vim .cmd ' Neotree reveal'
143+ end
144+ end ,
20145 },
21146 },
22- },
23- },
147+ commands = {
148+ trash = trash ,
149+ trash_visual = trash_visual ,
150+ },
151+ }
152+ end ,
24153}
0 commit comments