Closed JosefLitos closed 10 months ago
Initial investigation: might related to autocmd cruft from the original Vim— we've had issues with that before. (Specifically, BufNew
is fired when loading buffers from the shada file, but not BufRead
[Pre
/Post
]).
I have reproduced this issue without barbar.nvim
, so it's unrelated to this plugin. I'll try to come up with a snippet that can help mitigate it
How is this?
vim.api.nvim_create_autocmd('VimEnter', {callback = function()
if vim.api.nvim_cmd({cmd = 'args'}, {output = true}) == '' then -- if opening neovim without args
vim.api.nvim_command 'bdelete' -- delete the empty buffer
-- HACK: the next buffer won't have a filetype for… some reason. just re-set it.
local ft = vim.filetype.match {buf = 0}
vim.api.nvim_buf_set_option(0, 'filetype', ft)
end
end})
I just added a check for the ft
(can be nil when no other buffers were opened).
But it does the job very well, thanks a lot.
The only issue remaining is the filetype detection - even with this hack (or similarly with vim.bo.ft = ft
) lsp won't get loaded (when loaded by plugin lazy loaded by given filetype - neodev on ft='lua'
)
Final solution:
vim.api.nvim_create_autocmd('VimEnter', {
callback = function()
if #vim.v.argv < 3 and vim.fn.bufnr '$' > 1 then -- no args and other buffers opened
vim.cmd.bdelete()
local ft = vim.filetype.match { buf = 0 }
if ft then
vim.bo.ft = ft
vim.api.nvim_exec_autocmds('FileType', { pattern = ft })
end
end
end,
})
Thanks for posting the updated solution! Very strange that the filetype is cleared at all.
Description
Occurs when using '%' in shada to open all files from previously closed instance on startup. I end up being focused on an empty buffer
[buffer 1]
instead of the first file being opened.To Reproduce
init.vim:
Steps to reproduce the behavior:
Informations Neovim version: 0.10
It is possible that this is default behaviour of neovim, if that's the case, is there any way I could mitigate this?