Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Navigating inside an already open and showing terminal does not enter insert mode #455

Open
1 task done
uloco opened this issue Jul 3, 2023 · 5 comments
Open
1 task done

Comments

@uloco
Copy link

uloco commented Jul 3, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When a terminal is already open and showing and I navigate into another buffer split and go back to the terminal again, it does not enter inser mode. I have terminal_mapping and inser_mapping set to true. When opening the terminal with the mapping it works but once I navigate out and let it open, it does not enter insert automatically again.

I tried setting up a autocmd for TermEnter and BufEnter for term:https://* pattern but was not able to manage to do it.
Like so:

-- Auto insert mode when entering terminal
local augroup_term_insert = vim.api.nvim_create_augroup("Term-Insert", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter", "WinEnter", "TermOpen", "TermEnter" }, {
  group = augroup_term_insert,
  pattern = 'term:https://*',
  command = 'startinsert'
})

I am not sure if this should already work and is a configuration issue on my side or if the terminal_mapping only works for opening and closing the terminal by design.

Expected Behavior

navigating out and inside to the terminal buffer should work as expected. when coming back to the terminal buffer, enter insert mode, like when opening it with mapping.

Steps To Reproduce

setup toggleterm with the default config

Environment

- OS: macOS 13.4.1 (22F82)
- neovim version: v0.9.1
- Shell: zsh 5.9 (x86_64-apple-darwin22.0)

Anything else?

No response

@uloco
Copy link
Author

uloco commented Jul 3, 2023

I did some restructuring of my config and now it looks like it is working with the custom autocommand. sorry for the spam. but still maybe the default config could add this behaviour out of the box?

@elverskog
Copy link

@uloco I'm experiencing the same issue you described.
Can you share the changes you made?

@uloco
Copy link
Author

uloco commented Sep 28, 2023

I still have the same issue, didn't have time to fix it yet

@elverskog
Copy link

elverskog commented Sep 29, 2023

Ty.
As, you mentioned, I'll see if I can get an insert command firing on/after focus.

I'll just chime in and say I still see this more as a feature request or a bug.
Especially if the start_in_insert flag is set to true and the term was in insert mode when it lost focus.

Personally, going into "non-insert mode" in a terminal, as a default, doesn't ever make sense to me (I don't know what I'd do in that mode).

But, of course, going into "non-insert-mode" is the default for opening a terminal in neovim; outside of toggleterm
So this will likely always require a config/workaround somewhere.

@amsesk
Copy link
Contributor

amsesk commented Jan 30, 2024

I was having a similar problem and fixed it by following the advice here: #473 (comment)

If you are using "<C-\><C-n><C-W>w" style commands in your keymaps to switch out of terminal mode, switch it over to using wincmd instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants