Skip to content

Commit 0699a36

Browse files
committed
chore: replace neotree with snacks.explorer
1 parent 7344d78 commit 0699a36

File tree

2 files changed

+63
-21
lines changed

2 files changed

+63
-21
lines changed

lua/custom/plugins/snacks.lua

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ return {
2323
-- Useful for getting pretty icons, but requires a Nerd Font.
2424
{ 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
2525
},
26+
---@type snacks.Config
2627
opts = {
2728
bigfile = { enabled = true },
29+
explorer = {
30+
replace_netrw = true,
31+
},
2832
dashboard = {
2933
enabled = true,
3034
sections = {
@@ -76,6 +80,9 @@ return {
7680
frecency = true, -- frecency bonus
7781
history_bonus = true, -- give more weight to chronological order
7882
},
83+
sources = {
84+
explorer = {},
85+
},
7986
},
8087
quickfile = { enabled = true },
8188
statuscolumn = { enabled = true },
@@ -111,12 +118,47 @@ return {
111118
desc = '[S]earch [:]Command History',
112119
},
113120
{
114-
'<leader>se',
121+
'<leader>e',
115122
function()
116123
Snacks.explorer()
117124
end,
118125
desc = 'File Explorer',
119126
},
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+
},
120162
{
121163
'<leader>sf',
122164
function()

lua/kickstart/plugins/neo-tree.lua

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
-- https://github.com/nvim-neo-tree/neo-tree.nvim
33

44
return {
5-
'nvim-neo-tree/neo-tree.nvim',
6-
version = '*',
7-
dependencies = {
8-
'nvim-lua/plenary.nvim',
9-
'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended
10-
'MunifTanjim/nui.nvim',
11-
},
12-
lazy = false,
13-
keys = {
14-
{ '\\', ':Neotree reveal<CR>', desc = 'NeoTree reveal', silent = true },
15-
},
16-
opts = {
17-
filesystem = {
18-
window = {
19-
mappings = {
20-
['\\'] = 'close_window',
21-
},
22-
},
23-
},
24-
},
5+
-- 'nvim-neo-tree/neo-tree.nvim',
6+
-- version = '*',
7+
-- dependencies = {
8+
-- 'nvim-lua/plenary.nvim',
9+
-- 'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended
10+
-- 'MunifTanjim/nui.nvim',
11+
-- },
12+
-- lazy = false,
13+
-- keys = {
14+
-- { '\\', ':Neotree reveal<CR>', desc = 'NeoTree reveal', silent = true },
15+
-- },
16+
-- opts = {
17+
-- filesystem = {
18+
-- window = {
19+
-- mappings = {
20+
-- ['\\'] = 'close_window',
21+
-- },
22+
-- },
23+
-- },
24+
-- },
2525
}

0 commit comments

Comments
 (0)