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

[BUG] Leader "<space>" lags in toggleterm with no imap/tmap and insert_mappings=false #510

Closed dennisbakhuis closed 9 months ago

dennisbakhuis commented 10 months ago

Is there an existing issue for this?

Current Behavior

When using ToggleTerm in the terminal the lags as if a is pressed.

Using verbose imap <leader> and verbose tmap <leader> no mappings are found. In ToggleTerm config I explicitly set insert_mapping = false.

With the regular :terminal the space is not lagging.

Expected Behavior

I expect the to be not lagging

Steps To Reproduce

  1. MacOs with latest Wezterm and Neovim 0.9.4 and Lazy
  2. Using this config:
    
    return   {
    'akinsho/toggleterm.nvim',
    version = "*",
    config = function()
        require("toggleterm").setup {
            size = function(term)
                if term.direction == "horizontal" then
                    return 15
                elseif term.direction == "vertical" then
                    return vim.o.columns * 0.4
                end
            end,
            open_mapping = [[<leader>tt]],
            start_in_insert = true,
            insert_mappings = false,
            persist_size = true,
            direction = "horizontal",
        }
    end,
    }

### Environment

```Markdown
- OS: MacOs 14.1.1
- neovim version: 0.9.4
- Shell: Zsh 5.9

Anything else?

Thanks for this nice plugin

I feel a bit stupid for not finding the reason why it is lagging but I also do not seem to find a solution so I have a feeling it is how I have configured it.

dennisbakhuis commented 9 months ago

I think I solved my own problem 🎉

The "open_mapping" of course had a and as we are toggling, this mapping is aparently also applied in insert mode. Interestingly, this mapping did not turn up in verbose {i,t}map <leader>.

For future selfs and people like me, this is my working config:

return   {
    'akinsho/toggleterm.nvim',
    version = "*",
    config = function()
        require("toggleterm").setup {
            size = function(term)
                if term.direction == "horizontal" then
                    return 15
                elseif term.direction == "vertical" then
                    return vim.o.columns * 0.4
                end
            end,
            -- open_mapping = [[<leader>tt]],
            start_in_insert = true,
            insert_mappings = false,
            persist_size = true,
            direction = "horizontal",
        }

        -------------------------
        -- additional keybindings
        -------------------------
        -- toggle terminal
        vim.keymap.set('n', '<C-Enter>', [[<Cmd>ToggleTerm<CR>]], {})
        vim.keymap.set('t', '<C-Enter>', [[<Cmd>ToggleTerm<CR>]], {})

        -- open a vertical terminal if new
        vim.keymap.set('n', '<leader>tv', [[<Cmd>ToggleTerm direction=vertical<CR>]], {})

        -- open a horizontal terminal if new
        vim.keymap.set('n', '<leader>th', [[<Cmd>ToggleTerm direction=horizontal<CR>]], {})

        -- move to other windows
        vim.keymap.set('t', '<C-h>', [[<C-\><C-n><C-w>h]], {noremap = true})
        vim.keymap.set('t', '<C-j>', [[<C-\><C-n><C-w>j]], {noremap = true})
        vim.keymap.set('t', '<C-k>', [[<C-\><C-n><C-w>k]], {noremap = true})
        vim.keymap.set('t', '<C-l>', [[<C-\><C-n><C-w>l]], {noremap = true})

        -- copy to clipboard
        vim.keymap.set('t', '<C-y>', [[<C-\><C-n>"+yi]], {noremap = true})

        -- paste from clipboard
        vim.keymap.set('t', '<C-p>', [[<C-\><C-n>"+pi]], {noremap = true})
    end,
}

Thanks again for this nice plugin.

grimm26 commented 9 months ago

So are you saying that insert_mappings = false did not work?

diegodario88 commented 5 months ago

Hey there! I'm really curious about this too! Could you share how you managed to solve the problem? I'm struggling with it as well, and I'd really appreciate your help in clarifying things for me. Thanks a bunch!