How to make MiniSessions.restart() not open empty buffer with directory name #2410
-
Contributing guidelines
Module(s)mini.sessions Question
This buffer matches the directory I opened neovim with in step 1. I also have this auto command which affects the startup process: vim.api.nvim_create_autocmd('VimEnter', {
desc = ' Open file picker when passing a directory: `nvim <dir>`',
once = true, -- one shot
nested = true, -- handle other autocmds, like FileType
callback = function(data)
local is_dir = vim.fn.isdirectory(data.file) == 1
if is_dir then
vim.cmd.cd(data.file)
MiniPick.builtin.files()
-- Delete the empty buffer neovim creates when passing a directory.
vim.api.nvim_buf_delete(data.buf, { force = true })
end
end,
})How do I make |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
|
What do you use to display buffers (for example, bufferline.nvim or mini.tabline)? I assume that opening Neovim in a directory also opens the default file manager (netrw) as a buffer named after that directory. So the question is: why is that a problem, or more importantly, where is it being displayed? |
Beta Was this translation helpful? Give feedback.
-
|
I think this is a somewhat unintended behavior of The more concise way to reproduce this would be:
I'll take a look. |
Beta Was this translation helpful? Give feedback.
-
|
@andradei, I noticed that the picker also activates on restart. I could imagine that this is not needed when restarting with mini.sessions. EDIT: Removed incorrect lua example... Using require('mini.sessions').setup()
require('mini.pick').setup()
local directory_argument = nil
vim.api.nvim_create_autocmd('VimEnter', {
desc = ' Open file picker when passing a directory: `nvim <dir>`',
once = true, -- one shot
nested = true, -- handle other autocmds, like FileType
callback = function(data)
local is_dir = vim.fn.isdirectory(data.file) == 1
if is_dir then
directory_argument = data.file
vim.cmd.cd(directory_argument)
MiniPick.builtin.files()
end
end,
})
vim.api.nvim_create_autocmd('UIEnter', {
desc = 'Delete buffer created when passing a directory: `nvim <dir>`',
once = true,
callback = function()
if not directory_argument then return end
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_get_name(buf) == directory_argument then vim.api.nvim_buf_delete(buf, { force = true }) end
end
end,
})
|
Beta Was this translation helpful? Give feedback.
-
|
Would it be an idea to add a variant of the |
Beta Was this translation helpful? Give feedback.
Yeah, it seems to be a combination of two things:
:mksessionalways preserves argument list. It can be fixed on 'mini.sessions' side.:restartcommand always restarts respecting arguments passed before--, likenvim ~/.config/nvim. This is documented and can not be fixed on 'mini.sessions' side (the responsiblev:argfvariable is read-only). This behavior will probably be revised.So @andradei, if you want to not have this behavior, my best suggestions are:
Use
nvim -- ~/.config/nvimto open directories.Append the autocommand from the original comment withNot ne…vim.cmd('%argdelete'). This will clear the argument list on top of deleting the buffer for the opened directory.