How can I run mini.starter when opening a directory? #746
-
When I run |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Unfortunately, this is not as easy as it might seem. I learnt it the hard way in 'mini.files'. Basically, there are two steps to achieve this:
The most robust way to do this comes from 'mini.files' (this part and this part. And for the case of 'mini.starter' it can be done with something like this: -- Stop 'netrw' from taking over when directory path is edited
vim.cmd('silent! autocmd! FileExplorer *')
vim.cmd('autocmd VimEnter * ++once silent! autocmd! FileExplorer *')
-- Open Starter buffer when directory path is edited
local open_starter_on_dir = function(data)
-- Make early returns
if vim.api.nvim_get_current_buf() ~= data.buf then return end
if vim.b.ministarter_processed_dir then return vim.api.nvim_buf_delete(data.buf, { force = true }) end
local path = vim.api.nvim_buf_get_name(0)
if vim.fn.isdirectory(path) ~= 1 then return end
-- Show starter buffer
vim.bo.bufhidden = 'wipe'
vim.b.ministarter_processed_dir = true
vim.schedule(MiniStarter.open)
end
vim.api.nvim_create_autocmd('BufEnter', { callback = open_starter_on_dir }) All parts with |
Beta Was this translation helpful? Give feedback.
Unfortunately, this is not as easy as it might seem. I learnt it the hard way in 'mini.files'.
Basically, there are two steps to achieve this:
BufEnter
event to decide whether a buffer is for directory and if it is, open Starter buffer.The most robust way to do this comes from 'mini.files' (this part and this part. And for the case of 'mini.starter' it can be done with something like this: