voldikss / vim-floaterm

:computer: Terminal manager for (neo)vim
MIT License
2.5k stars 80 forks source link

Is it possible to change when floaterm opens when toggling? #338

Open medwatt opened 2 years ago

medwatt commented 2 years ago

My default settings is currently to open terminals on the right. However, there are some cases when vim is occupying have of my screen real-estate and, in those cases, I would like the same terminal to now open on the bottom when I toggle it.

I can write a function that does exactly that, but I would it to work when toggling, not when opening a new terminal. Can this be done?

local open_floaterm = function()
    local width = vim.o.columns
    local height = vim.o.lines
    if width > 100 then
        -- open vertically
    else
        -- open horizontally
    end
end
adigitoleo commented 2 years ago

When a hidden floaterm is shown, window config is read from buffer local variables, using floaterm#config#get_all().

If you keep track of the buffer number, you should be able to modify the options with setbufvar() before showing the floaterm.

In this case, you need e.g. setbufvar(<bufnr>, 'floaterm_wintype', 'split') (or vsplit for vertical).

I tested it by opening a floaterm, using :echo bufnr() to check the number, then :FloatermHide. Modify the wintype using command as above, then :FloatermShow.

I haven't used the lua API but I imagine the command names are similar.