patch 9.2.0200: term: DECRQM codes are sent too early
Commit:
https://github.com/vim/vim/commit/1da42ee2710c7d3413e0656cbbc9067f23390615
Author: Foxe Chen <
chen...@gmail.com>
Date: Thu Mar 19 19:10:32 2026 +0000
patch 9.2.0200: term: DECRQM codes are sent too early
Problem: term: DECRQM codes are sent too early, the resulting DECRPM
responses can arrive after Vim has already exited, leaking
into the shell's input buffer (Christian Brabandt).
Solution: Only send DECRQM codes once termcap_active is set
(Foxe Chen).
related: #19660
fixes: #19660#issuecomment-
4085448070
closes: #19748
Signed-off-by: Foxe Chen <
chen...@gmail.com>
Signed-off-by: Christian Brabandt <
c...@256bit.org>
diff --git a/src/main.c b/src/main.c
index 9f9fd1205..b5f542a49 100644
--- a/src/main.c
+++ b/src/main.c
@@ -893,6 +893,9 @@ vim_main2(void)
may_req_bg_color();
# endif
+ // Same reason for termresponse, don't want the terminal sending out the
+ // DECRPM response after Vim has exited.
+ send_decrqm_modes();
// start in insert mode
if (p_im)
diff --git a/src/proto/
term.pro b/src/proto/
term.pro
index 9653a35af..82c794f4f 100644
--- a/src/proto/
term.pro
+++ b/src/proto/
term.pro
@@ -96,6 +96,7 @@ void swap_tcap(void);
void ansi_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u *ansi_idx);
void cterm_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u *ansi_idx);
int term_replace_keycodes(char_u *ta_buf, int ta_len, int len_arg);
+void send_decrqm_modes(void);
void term_disable_dec(void);
void term_set_win_resize(bool state);
void term_set_sync_output(int flags);
diff --git a/src/term.c b/src/term.c
index e9cb91cdc..5e19b09a9 100644
--- a/src/term.c
+++ b/src/term.c
@@ -4051,16 +4051,6 @@ starttermcap(void)
out_str(T_FE);
#endif
- if (cur_tmode == TMODE_RAW)
- {
- // Request setting of relevant DEC modes via DECRQM
- for (int i = 0; i < (int)ARRAY_LENGTH(dec_modes); i++)
- {
- vim_snprintf((char *)IObuff, IOSIZE, " [?%d$p", dec_modes[i]);
- out_str(IObuff);
- }
- }
-
out_flush();
termcap_active = TRUE;
screen_start(); // don't know where cursor is now
@@ -7981,6 +7971,23 @@ term_replace_keycodes(char_u *ta_buf, int ta_len, int len_arg)
return len;
}
+/*
+ * Query the settings for the DEC modes we support
+ */
+ void
+send_decrqm_modes(void)
+{
+ if (termcap_active && cur_tmode == TMODE_RAW)
+ {
+ // Request setting of relevant DEC modes via DECRQM
+ for (int i = 0; i < (int)ARRAY_LENGTH(dec_modes); i++)
+ {
+ vim_snprintf((char *)IObuff, IOSIZE, " [?%d$p", dec_modes[i]);
+ out_str(IObuff);
+ }
+ }
+}
+
/*
* Should be called when cleaning up terminal state.
*/
diff --git a/src/version.c b/src/version.c
index a82c17186..b1088289f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 200,
/**/
199,
/**/