numToStr / FTerm.nvim

:fire: No-nonsense floating terminal plugin for neovim :fire:
MIT License
721 stars 24 forks source link

I have two opened fterm windows, how to auto close the second fterm window when the first fterm window opened? #97

Closed jonahfang closed 8 months ago

jonahfang commented 8 months ago

My current configuration like this (F11 to show the first fterm window, and F12 to show the second window):

return {
    "numToStr/FTerm.nvim",
    pin = true,
    lazy = false,
    config = function()
        local fterm = require("FTerm")
        fterm.setup({
            border = 'single',
            dimensions  = {
                height = 0.7,
                width = 1.0,
                x = 0,
                y = 0,
            },
        })
        local load_fish_config_cmd = 'source ~/fish\nc\n'

        -- first terminal
        vim.api.nvim_create_user_command('FirstFishFTerminal', function()
            fterm.toggle()
        end, { bang = true })
        vim.keymap.set('n', '<F11>', "<CMD>FirstFishFTerminal<CR>")
        vim.keymap.set('t', '<F11>', "<C-\\><C-n><CMD>FirstFishFTerminal<CR>")

        -- second terminal
        local fnew = fterm:new({
            ft = 'fterm_fnew', -- You can also override the default filetype, if you want
            dimensions = {
                height = 0.7,
                width = 0.9
            }
        })
        vim.api.nvim_create_user_command('SecondFishFTerminal', function()
           fnew:toggle()
        end, { bang = true })
        vim.keymap.set('n', '<F12>', "<CMD>SecondFishFTerminal<CR>")
        vim.keymap.set('t', '<F12>', "<C-\\><C-n><CMD>SecondFishFTerminal<CR>")
    end
}
-- EOP
jonahfang commented 8 months ago

I defined a key map to close two fterm windows once:

        vim.keymap.set('t', '<leader>x', function()
           fterm.close()
           fnew:close()
        end)