akinsho / toggleterm.nvim

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

[BUG] open_mapping keybinding only works after `:ToggleTerm` has been called before #575

Closed jmpargana closed 4 months ago

jmpargana commented 5 months ago

Is there an existing issue for this?

Current Behavior

When I open neovim and use the open_mapping (ex. <c-\>) nothing happens. After I run :ToggleTerm for the first time the mapping becomes available and starts working to open and close the terminal.

I've tried changing the open_mapping option or sticking to the default but nothing changes.

Expected Behavior

Configured mapping should work before running command.

Steps To Reproduce

  1. Using the versions listed below, setup a minimal neovim with the following config:
    
    {
    'akinsho/toggleterm.nvim',
    version = '*',
    opts = {
      open_mapping = [[<c-\>]],
    },
    keys = {
      { '<C-t>', '<cmd>ToggleTerm<cr>', desc = '[T]oggle [T]erm' },
    },
    },
2. Launch `nvim` and try to toggle terminal with defined config

### Environment

```Markdown
- OS: MacOS 14.4 (23E214)
- neovim version: NVIM v0.9.5
- Shell: zsh 5.9 (x86_64-apple-darwin23.0)

Anything else?

I'be happy to contribute to this repository by fixing this bug if you giving me some pointers :)

jmpargana commented 5 months ago

After investigating I've noticed that lazy.nvim is not loading the plugin. Running lua require("toggleterm").setup {} or sourcing the toggleterm.lua file loads makes the open_mapping available. I've tried to use the default configuration suggested in the README, but it has the same problem.

Do you have any pointers?

Screenshot 2024-04-24 at 18 17 17
mixtli commented 4 months ago

The open_mapping is not working for me either.

tkkcc commented 4 months ago

you use lazy's key config, this will make it lazy load on key press, https://github.com/folke/lazy.nvim?tab=readme-ov-file#-plugin-spec

you can set lazy to false besides key, or rich the key config for all bindings you need.

jmpargana commented 4 months ago

you use lazy's key config, this will make it lazy load on key press, https://github.com/folke/lazy.nvim?tab=readme-ov-file#-plugin-spec

you can set lazy to false besides key, or rich the key config for all bindings you need.

Thank you that fixed it :)