akinsho / toggleterm.nvim

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

How do I close the terminal with the same keybindings? #587

Closed rew1nter closed 1 month ago

rew1nter commented 1 month ago

My current code looks like this

    'akinsho/toggleterm.nvim', 
    version = "*", 
    opts = {--[[ things you want to change go here]]},
    config = function() 
        require("toggleterm").setup()       
        vim.keymap.set('n', '<space>i', ':ToggleTerm direction=float<CR>')
    end

I want the same keymap to close the terminal

rew1nter commented 1 month ago

I've also tried this. Here leader-g doesn't close the terminal when focused

        local Terminal  = require('toggleterm.terminal').Terminal
        local lazygit = Terminal:new({direction = 'float'})

        function _lazygit_toggle()
            lazygit:toggle()
        end

        vim.api.nvim_set_keymap("n", "<leader>g", "<cmd>lua _lazygit_toggle()<CR>", {noremap = true, silent = true})