akinsho / toggleterm.nvim

A neovim lua plugin to help easily manage multiple terminal windows
GNU General Public License v3.0
4.21k stars 170 forks source link

Is it possible to allow users to open the toggleterm in the current window, just like :term? #528

Open nullptr-yxw opened 8 months ago

nullptr-yxw commented 8 months ago

It might be quite difficult to manage the window of the toggleterm(for example, #97 and #484), so is it possible to allow users opening the toggleterm in the current window(direction="buffer"), just like:term? So that the manage of the toggleterm window will be more flexible. And the users can use some commands such as tab or setlocal nobuflisted to change the performance as well.

blurskye commented 6 months ago

well yes it is possible but quite useless... here is a snippet from my plugin... .......

    local buf_type = vim.api.nvim_buf_get_option(vim.api.nvim_get_current_buf(), 'buftype')
    local terminal_buf_found = false
    if buf_type ~= 'terminal' then
        local buffers = vim.api.nvim_list_bufs()
        for _, buf in ipairs(buffers) do
            if vim.api.nvim_buf_get_option(buf, 'buftype') == 'terminal' then
                vim.api.nvim_win_set_buf(vim.api.nvim_get_current_win(), buf)
                terminal_buf_found = true
                break
            end
        end
        if not terminal_buf_found then

            vim.api.nvim_exec(':ToggleTerm', false)
        end
    end

the snippet is for a different usecase, in trying to send ctrl+c to the terminal, but maybe thats all you need to write a custom script to achieve what you want