@@ -23,8 +23,12 @@ return {
23
23
-- Useful for getting pretty icons, but requires a Nerd Font.
24
24
{ ' nvim-tree/nvim-web-devicons' , enabled = vim .g .have_nerd_font },
25
25
},
26
+ --- @type snacks.Config
26
27
opts = {
27
28
bigfile = { enabled = true },
29
+ explorer = {
30
+ replace_netrw = true ,
31
+ },
28
32
dashboard = {
29
33
enabled = true ,
30
34
sections = {
@@ -76,6 +80,9 @@ return {
76
80
frecency = true , -- frecency bonus
77
81
history_bonus = true , -- give more weight to chronological order
78
82
},
83
+ sources = {
84
+ explorer = {},
85
+ },
79
86
},
80
87
quickfile = { enabled = true },
81
88
statuscolumn = { enabled = true },
@@ -111,12 +118,47 @@ return {
111
118
desc = ' [S]earch [:]Command History' ,
112
119
},
113
120
{
114
- ' <leader>se ' ,
121
+ ' <leader>e ' ,
115
122
function ()
116
123
Snacks .explorer ()
117
124
end ,
118
125
desc = ' File Explorer' ,
119
126
},
127
+ {
128
+ ' \\ ' ,
129
+ desc = ' File Explorer Toggle' ,
130
+ -- Based on https://www.reddit.com/r/neovim/comments/1k7rkfp/comment/mp2j44i
131
+ (function ()
132
+ -- Create a closure to store both previous buffer and window
133
+ local previous_buffer = nil
134
+ local previous_window = nil
135
+
136
+ return function ()
137
+ local explorer_pickers = Snacks .picker .get { source = ' explorer' }
138
+ -- Check if there are any explorer pickers open
139
+ if # explorer_pickers == 0 then
140
+ -- If none exist, store current buffer/window and open a new explorer picker
141
+ previous_buffer = vim .api .nvim_get_current_buf ()
142
+ previous_window = vim .api .nvim_get_current_win ()
143
+ Snacks .picker .explorer ()
144
+ elseif explorer_pickers [1 ]:is_focused () then
145
+ -- If the explorer is already focused, close it and return to previous buffer/window
146
+ -- explorer_pickers[1]:close()
147
+ if previous_buffer and vim .api .nvim_buf_is_valid (previous_buffer ) and previous_window and vim .api .nvim_win_is_valid (previous_window ) then
148
+ -- Focus the previous window first
149
+ vim .api .nvim_set_current_win (previous_window )
150
+ -- Then set the buffer in that window
151
+ vim .api .nvim_win_set_buf (previous_window , previous_buffer )
152
+ end
153
+ else
154
+ -- If the explorer exists but isn't focused, store current buffer/window and focus explorer
155
+ previous_buffer = vim .api .nvim_get_current_buf ()
156
+ previous_window = vim .api .nvim_get_current_win ()
157
+ explorer_pickers [1 ]:focus ()
158
+ end
159
+ end
160
+ end )(),
161
+ },
120
162
{
121
163
' <leader>sf' ,
122
164
function ()
0 commit comments