akinsho / toggleterm.nvim

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

fix: set_mode may not be taken into account #596

Closed pipoprods closed 1 month ago

pipoprods commented 1 month ago

I'm using quick-access shortcuts to switch to a given terminal:

            { "<M-&>", "<cmd>1 ToggleTerm<cr>", mode = { "n", "t" }, desc = "Toggle terminal 1" },
            { "<M-é>", "<cmd>2 ToggleTerm<cr>", mode = { "n", "t" }, desc = "Toggle terminal 2" },
            { '<M-">', "<cmd>3 ToggleTerm<cr>", mode = { "n", "t" }, desc = "Toggle terminal 3" },
            { "<M-'>", "<cmd>4 ToggleTerm<cr>", mode = { "n", "t" }, desc = "Toggle terminal 4" },
            { "<M-(>", "<cmd>5 ToggleTerm<cr>", mode = { "n", "t" }, desc = "Toggle terminal 5" },
            { "<M-->", "<cmd>6 ToggleTerm<cr>", mode = { "n", "t" }, desc = "Toggle terminal 6" },
            { "<M-è>", "<cmd>7 ToggleTerm<cr>", mode = { "n", "t" }, desc = "Toggle terminal 7" },
            { "<M-_>", "<cmd>8 ToggleTerm<cr>", mode = { "n", "t" }, desc = "Toggle terminal 8" },
            { "<M-ç>", "<cmd>9 ToggleTerm<cr>", mode = { "n", "t" }, desc = "Toggle terminal 9" },
            { "<M-à>", "<cmd>10 ToggleTerm<cr>", mode = { "n", "t" }, desc = "Toggle terminal 10" },

With this setup, every time I switch from one terminal to another, the terminal is placed in normal mode.

This PR postpones the set_mode command so the mode gets what is expected.

akinsho commented 1 month ago

🤞🏿 let's hope nothing breaks, thanks for the PR

augustocdias commented 1 month ago

I wonder if this is the culprit of some weird behaviors I'm seeing lately... I have an autocmd to set the term in insert mode on BufEnter and that just stopped working. Sometimes it fails to leave insert mode either. All of this is just random. I couldn't figure out yet what triggers these problems.

pipoprods commented 3 weeks ago

@augustocdias Did you try postponing your autocmd with a vim.schedule? Does the behavior change? Could you post a relevant part of your config so I can test it on my side?

augustocdias commented 2 weeks ago

@pipoprods this is the toggleterm config: https://github.com/augustocdias/dotfiles/blob/main/.config/nvim/lua/setup/toggleterm.lua

and those are my autocmds:

https://github.com/augustocdias/dotfiles/blob/main/.config/nvim/lua/setup/autocommand.lua#L2-L32

I can't find a consistent way to reproduce it... I also have an issue sometimes where the term just doesn't leave insert mode... I have to kill it and start it again.