[mini.files] Auto resize preview window width when resize terminal windows. #1564
-
Contributing guidelines
Module(s)mini.files QuestionI did this autocmd but it broken synchronization detection, vim.api.nvim_create_autocmd("WinResized", { |
Beta Was this translation helpful? Give feedback.
Answered by
echasnovski
Feb 11, 2025
Replies: 1 comment 1 reply
-
|
There are several issues here:
Taking into account all of that, the following setup works: require('mini.files').setup({
windows = {
preview = true,
width_focus = 37,
width_preview = vim.o.columns - 41,
},
})
vim.api.nvim_create_autocmd('VimResized', {
callback = function()
local new_width_preview = vim.o.columns - 41
-- Update current explorer (if any)
MiniFiles.refresh({ windows = { width_preview = new_width_preview } })
-- Update config for all future explorers
MiniFiles.config.windows.width_preview = new_width_preview
end,
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
echasnovski
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are several issues here:
WinResizedis not the right event for this as it triggers whenever regular Neovim window is resized. You'd wantVimResizedto detect when terminal's instance is resized.setup()is a bit too much in this particular context. In general, executingsetup()for any 'mini.nvim' module is recommended to 1) enable plugin with its initial config; or 2) perform an action that is specific tosetup()(like create mappings). For "on the fly" config modification it is usually enough to modifyconfigfield (in this caseMiniFiles.config) directly. See more "Setup" section of "General principles".MiniFiles.refresh()to update the config of the currentl…