undotree icon indicating copy to clipboard operation
undotree copied to clipboard

how do i reset the window size from the last time

Open HUAHUAI23 opened this issue 3 years ago • 3 comments

https://user-images.githubusercontent.com/43649186/193557293-73aea9f5-a354-4b5a-9ca1-12ca3b191f34.mp4

HUAHUAI23 avatar Oct 03 '22 10:10 HUAHUAI23

The undotree window will remember its width so that you don't have to resize it (e.g. when the line width is not long enough to show all the info) every time you bring it up. In this case when you close the file tree the undotree window gets resized automatically. Although it might not be the intention of the user, that's the default behavior of vim. You can try to manually resize the undotree window with mouse or resizing command but if you need the panel to restore to its original size even after it gets automatically resized, you may try to hack the plugin to add some resizing autocommand on some events like bufenter.

mbbill avatar Oct 05 '22 08:10 mbbill

@HUAHUAI23 can you please post the solution if you come up with anything.

arihans avatar Oct 18 '22 13:10 arihans

i solved this

local api = vim.api

local function setUndotreeWinSize()
	local winList = api.nvim_list_wins()
	for _, winHandle in ipairs(winList) do
		if
			api.nvim_win_is_valid(winHandle)
			and api.nvim_buf_get_option(api.nvim_win_get_buf(winHandle), "filetype") == "undotree"
		then
			api.nvim_win_set_width(winHandle, vim.g.undotree_SplitWidth)
		end
	end
end
api.nvim_create_user_command("Ut", function()
	api.nvim_cmd(api.nvim_parse_cmd("UndotreeToggle", {}), {})
	setUndotreeWinSize()
end, { desc = "load undotree" })

wrap UndotreeToggle command with mine,it will set undotree window size

HUAHUAI23 avatar Nov 05 '22 04:11 HUAHUAI23