toggleterm.nvim icon indicating copy to clipboard operation
toggleterm.nvim copied to clipboard

[Regression] Toggling tabs opens in 'normal mode' and do not close

Open Grazfather opened this issue 1 year ago • 9 comments

Noticed this just today.

Sometimes, after using nvim for a while and opening the terminal a few times, when I toggle the terminal it shows NORMAL mode. I have to hit i to get into TERMINAL mode.

I am on commit 5ea8233 on nvim v0.8.0 dev, not sure the specific dev commit, on ubuntu

Grazfather avatar Aug 04 '22 18:08 Grazfather

@Grazfather this is probably because of the persist_mode = true and probably using terminal mappings that don't use wincmd I've added a notice about this in the README but the quickest solution is to set persist mode to false or carefully read the notice I've added and update your config

akinsho avatar Aug 04 '22 20:08 akinsho

I've just changed the default for this mode to false by default, since really I guess only people who have set up their mappings for it should be using it.

akinsho avatar Aug 04 '22 20:08 akinsho

I've updated to b9f7e08 and the issue still exists, actually, so I don't think that that's it.

Grazfather avatar Aug 05 '22 13:08 Grazfather

In which case, can you provide a minimal init.lua with steps for me to reproduce this myself.

akinsho avatar Aug 05 '22 13:08 akinsho

local execute = vim.api.nvim_command
local fn = vim.fn

local pack_path = fn.stdpath("data") .. "/site/pack"

-- Manually clones a <user>/<repo> from github into the pack directory. Used to
-- bootstrap.
local function ensure (user, repo)
    local install_path = string.format("%s/packer/start/%s", pack_path, repo, repo)
    if fn.empty(fn.glob(install_path)) > 0 then
        execute(string.format("!git clone https://github.com/%s/%s %s", user, repo, install_path))
        execute(string.format("packadd %s", repo))
    end
end

-- Packer is our plugin manager.
ensure("wbthomason", "packer.nvim")

local ok, packer = pcall(require, "packer")
if not ok then
    return
end

packer.startup(function(use)
  use {"akinsho/toggleterm.nvim"}
end)

require("toggleterm").setup({open_mapping = "<c-\\>", direction = "tab"})

Simply hit C-\\ three times and you'll be in the terminal in normal mode.

Grazfather avatar Aug 05 '22 14:08 Grazfather

@Grazfather from what I can see in your config you are not using start_in_insert so there isn't really a reason why the terminal should not start in normal mode. If you just run :terminal then by default neovim doesn't start a terminal in insert mode. The same applies here unless you set this plugin to behave differently

akinsho avatar Aug 08 '22 21:08 akinsho

Well, start_in_insert defaults to true, plus, I never needed it before (this seems to be a regression), and finally, setting it to true explicitly does not remediate the issue.

Were you able to reproduce with my init.lua?

Grazfather avatar Aug 09 '22 02:08 Grazfather

I couldn't initially reproduce this using splits, but it seems to specifically reproduce with tabs, although what I'm seeing is more that toggling tabs doesn't work well.

I'll re-open this issue and leave it to track the bug, but I don't have time to look into this currently, so it won't be high on my list. Please feel free to dig in and contribute if it's affecting your workflow.

akinsho avatar Aug 09 '22 07:08 akinsho

Thank you for taking a look. I will switch to float in the meantime, and I will try to take a look (though I do not know Vim's lua api very well at all).

Grazfather avatar Aug 09 '22 13:08 Grazfather

@Grazfather can you try the tab mode again and see if it behaves correctly on the latest commit?

akinsho avatar Aug 31 '22 10:08 akinsho

To be clear if start_in_insert = false, persist_mode = false the expected behaviour will be always in normal mode, unless explicitly set to do it, the terminal does not open in insert mode

akinsho avatar Aug 31 '22 11:08 akinsho

I am afraid I still have the issue on commit b402342. Is it fixed for you?

Grazfather avatar Sep 03 '22 14:09 Grazfather

@Grazfather can you clarify the issue exactly again, I'm no longer sure I know what is actually going wrong, do you expect the terminal to be in insert, and it's not despite some settings or vice versa?

akinsho avatar Sep 03 '22 14:09 akinsho

I do this:

  1. Open vim
  2. Open terminal, it is in insert mode, as expected.
  3. Toggle the terminal, back to my main buffer.
  4. Open the terminal now, no longer in insert mode.

Grazfather avatar Sep 03 '22 14:09 Grazfather

@Grazfather are you using start_in_insert = true and persist_mode = true ?

akinsho avatar Sep 03 '22 14:09 akinsho

If not then I would not expect the terminal to be in insert also if you are using persist mode have you changed your terminal mappings as mentioned in the notice in the readme?

akinsho avatar Sep 03 '22 14:09 akinsho

Yes I am using those settings. You should be able to repro with my minimal config above.

Grazfather avatar Sep 03 '22 14:09 Grazfather

@Grazfather think this should now be fixed, can you try again.

akinsho avatar Sep 03 '22 15:09 akinsho

It seems fixed at 7abb25e!

Grazfather avatar Sep 03 '22 15:09 Grazfather

👍🏿 should be now, seems the issue was that the mode wasn't being reset for tab pages due to a specific edge case

akinsho avatar Sep 03 '22 15:09 akinsho

Thanks for the fix!

Grazfather avatar Sep 03 '22 15:09 Grazfather

I was also just running into this issue. That commit works for me, thanks for fixing it!

willocho avatar Oct 14 '22 18:10 willocho