3

According to vim help, https://vimhelp.org/terminal.txt.html#t_CTRL-W_CTRL-C <C-w><C-c> will forcibly end the terminal job.

I've been unable to disable this; I've attempted many variations of the following:

:tnoremap <C-w><C-c> <Nop>

Unfortunately, what this achieves is quite strange; the mapping indeed makes a simultaneous combination of <C-w><C-c> do nothing; however, if one waits for several seconds after <C-w>, then decides to hit <C-c>, somehow the t_CTRL-W_CTRL-C still triggers, and promptly destroys my terminal.

How can we get this to work? Thanks.

user22476690
  • 143
  • 7
  • What is you only type in your terminal (without the <C-wW)? – Vivian De Smedt Sep 13 '23 at 14:00
  • 1
    Mappings time out, which is why you are able to wait a few seconds between keystrokes to invoke the native key binding. I don't know a way around this. – Heptite Sep 13 '23 at 15:01
  • @VivianDeSmedt I do. This usually happens when I decide halfway after thinking to switch to another window, but I remember that I wanted to do something on the terminal. This is rather annoying, since in a variety of places in vim, acts to cancel the current command-in-progress, and I'm accustomed to using it when I want to start a new action. – user22476690 Sep 13 '23 at 17:17
  • @Heptite No, I don't think that's the problem. I'm running bash in the terminal, so when I directly invoke without , bash simply prints "^C" on.the screen and stops the running command, if any. That's what I would expect and would like to happen, instead of vim closing my terminal. In fact, it has to be a forceful close as well, since if I otherwise try to ":q" on the terminal, vim will kindly remind me that "E948: Job still running (add ! to end the job". These indicate that vim is indeed somehow ignoring my mapping and actively bringing a "forcibly end". – user22476690 Sep 13 '23 at 17:20
  • @Heptite Oh, by native do you rather refer to the vim-native bindings? A quick search suggests that timeoutlen can change this; I wonder if I can configure it just for ? That would work for me. – user22476690 Sep 13 '23 at 17:23
  • Hmm I guess then the question is why termwinkey "remembers" the pressed key, despite timeout having elapsed. – user22476690 Sep 13 '23 at 17:37

1 Answers1

2

As @Heptite mentions, mappings are discarded after a timeout period. On the other hand, it seems like the terminal window commands aren't discarded after the same timeout period, causing native terminal-mode bindings to be recognised.

I'm resorting to turning off timeout whenever one is in the terminal mode to serve the purpose. This works decently as the terminal mode has virtually no bindings by default.

autocmd ModeChanged *:t set notimeout
autocmd ModeChanged t:* set timeout

It seems to work ok, except for the first window before I switch to any other window, in the case where I start vim with a terminal as the first window by "+:term ++curwin". I haven't been able to figure out the autocommands for that case, but I guess that behavior kind of makes sense in that case anyway.

user22476690
  • 143
  • 7
  • 1
    You can try setting notimeout by Default to handle the first window & let autocmd handle the later activities. – Prem Sep 13 '23 at 19:58