[vim/vim] Add autocommand events TerminalLeave (#7363)

18 views
Skip to first unread message

ZhiyuanLck

unread,
Nov 24, 2020, 11:18:07 PM11/24/20
to vim/vim, Subscribed

The problem is that I can not find a way to obtain the current mode before key <c-\><c-n> takes effect in terminal mode.

I want to restore the pos of cursor in terminal when reloading it in a popup:

  • If the mode was terminal when terminal popup is closed, feed 'a' to terminal when reopen it in popup
  • If the mode was normal before, record the pos of cursor before closing the popup and restore the pos when repoen the terminal in popup.

Cause actions such as recording modes, closing popup, restoring positions are done by functions, which means I need return from terminal mode to normal mode first by <c-\><c-n> and then call functions. If I perform record action in function, then I will alway got n through mode().

So if it possible to add a autocommands like InsertLeave and InsertLeavepre or there is some other way I do not know to handle such case.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

lacygoill

unread,
Nov 24, 2020, 11:40:32 PM11/24/20
to vim/vim, Subscribed

So if it possible to add autocommands like InsertLeave and InsertLeavepre

Relevant todo item:

https://github.com/vim/vim/blob/a09bee322e605c8a076fa23c3d3259495a1129d2/runtime/doc/todo.txt#L899-L900

or there is some other way I do not know to handle such case.

Cause actions such as recording modes, closing popup and restoring positions are done in functions, which means I need return from terminal mode to normal mode first by <c-> and then call functions. If I perform record action in function, then I will alway get n through mode().

When calling your function, try to use the pseudo-key <cmd> (require patch 8.2.1978):

tnoremap <key> <c-\><c-n>:call MyFunc()<cr>

               ^---------^

                    ✘



tnoremap <key> <cmd>call MyFunc()<cr>

               ^---^

                 ✔

Alternatively, you could try to emulate the TermEnter and TermLeave events by firing them manually via custom mappings. That's what I do in this gist.

ZhiyuanLck

unread,
Nov 24, 2020, 11:47:56 PM11/24/20
to vim/vim, Subscribed

When calling your function, try to use the pseudo-key <cmd> (require patch 8.2.1978):

tnoremap <key> <c-\><c-n>:call MyFunc()<cr>

               ^---------^

                    ✘



tnoremap <key> <cmd>call MyFunc()<cr>

               ^---^

                 ✔

It helps a lot! Thanks a lot.

lacygoill

unread,
Nov 24, 2020, 11:54:38 PM11/24/20
to vim/vim, Subscribed

Glad it helps. Note that there is already a bug report currently open which asks for a TermLeave event: #2487

lacygoill

unread,
Oct 22, 2021, 3:40:32 PM10/22/21
to vim/vim, Subscribed

Fixed in patch 8.2.3555.

Use ModeChanged nt:t instead of TerminalEnter and ModeChanged t:nt instead of TerminalLeave.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

Bram Moolenaar

unread,
Oct 22, 2021, 4:08:41 PM10/22/21
to vim/vim, Subscribed

Closed #7363.


You are receiving this because you are subscribed to this thread.

Reply all
Reply to author
Forward
0 new messages