s1n7ax / nvim-terminal

A Lua-Neovim plugin that toggles a terminal
MIT License
117 stars 6 forks source link

Respect embedded vim window resizing on toggle #2

Closed susliko closed 3 years ago

susliko commented 3 years ago

Thank you for this awesome plugin!

Here is an improvement suggestion

Problem

Whenever you resize your windows with vim embedded resize function, you might expect your toggling terminal windows to respect this setting after closing and opening them again (personally I even have these remaps: nnoremap <Up> :resize -2<CR> nnoremap <Down> :resize +2<CR>).

Now, whenever Window.close is executed, it doesn't memoize window's width and height. Next time Window.open is executed, it opens with its default settings

Solution

I tweaked it by modifying the Window.close function:

function Window:close(winid)
    if self:is_valid() then 
        self.width = v.nvim_win_get_width(self.windid)
        self.height = v.nvim_win_get_height(self.winid)
        v.nvim_win_close(self.winid, false) 
    end
end

My proposition is either to embed it as default behaviour or to make a setting for it

s1n7ax commented 3 years ago

@susliko Now you can simply call require('nvim-terminal').setup() to setup everything. More about keymaps and customization are available in the README. The configuration still should work regardless the new updates.