[mini.files] Auto-expand empty & nested dirs #1184
iparnelly
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
Thanks for sharing! This looks nice! The way I'd approach this, though, is via custom mapping. This looks more robust than local expand_single_dir
expand_single_dir = vim.schedule_wrap(function()
local is_one_dir = vim.api.nvim_buf_line_count(0) == 1 and (MiniFiles.get_fs_entry() or {}).fs_type == 'directory'
if not is_one_dir then return end
MiniFiles.go_in()
expand_single_dir()
end)
local go_in_and_expand = function()
MiniFiles.go_in()
expand_single_dir()
end
vim.api.nvim_create_autocmd('User', {
pattern = 'MiniFilesBufferCreate',
callback = function(args) vim.keymap.set('n', 'l', go_in_and_expand, { buffer = args.data.buf_id }) end,
})
require('mini.files').setup({ mappings = { go_in = '' } }) Mapping's LHS can be change to be something other than |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wrote a quick autocommand to automatically traverse directories that are empty outside of a single nested directory.
Screen.Recording.2024-08-29.at.2.40.58.PM.mov
Directory Structure for demo above:
Implementation
I basically just check if there is only 1 line in the buffer, and confirm that the entry is a directory. If it is, then I call
go_in
.I'm not lua-fluent (or even vim-api fluent) so if there are any issues you see that this might run into, let me know!
I ran into a nice recursive loop situation, hence the
vim.schedule
. Otherwise, things are pretty straightforward.Code:
Thanks
Beta Was this translation helpful? Give feedback.
All reactions