I recently started using Neovim for my text editing needs and that includes setting something up to manage files with. Because I used the NVChad distribution initially I stuck with nvim-tree. But after some searching I came across the mini.files plugin which works wondefully!
The only gripe I had with it is that the bookmarks feature was not persistent across sessions. I was already using the auto-session plugin so I configured it to also restore my bookmarks. Here is my config:
Save this into your init.lua
or wherever you setup your mini
plugins:
-- Bookmarks autosave
local set_mark = function(id, path)
MiniFiles.set_bookmark(id, path)
end
vim.api.nvim_create_autocmd('User', {
pattern = 'MiniFilesExplorerOpen',
callback = function()
if MiniFilesBookmarks ~= nil then
for id, mark in pairs(MiniFilesBookmarks) do
set_mark(id, mark.path)
end
end
end,
})
local save_marks = function()
local e = MiniFiles.get_explorer_state()
E = e
if e ~= nil then
MiniFilesBookmarks = e.bookmarks
end
end
vim.api.nvim_create_autocmd('User', {
pattern = 'MiniFilesExplorerClose',
callback = save_marks,
})
And configure your auto-session
plugin like this, I am using lazy
for my configuration.
{
'rmagatti/auto-session',
lazy = false,
opts = {
save_extra_cmds = {
function()
if MiniFilesBookmarks == nil then
return
end
local t = vim.inspect(MiniFilesBookmarks):gsub('[\n\r]', ' ')
return 'lua MiniFilesBookmarks=' .. t
end,
},
},
}
Hopefully this quick blog post was helpful to anyone that encounters the same problem!