[vim/vim] feat: add TermResponseOSC autocommand (PR #17975)

78 views
Skip to first unread message

Foxe Chen

unread,
Aug 12, 2025, 12:26:57 AMAug 12
to vim/vim, Subscribed

Adds an autocommand TermResponseOSC and a vim var v:termosc that captures the OSC response. This allows for stuff such as the OSC 52 command. Currently can't capture responses larger than the typeahead buffer, I am working on it.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/17975

Commit Summary

  • b1ffdfc initial commit: add TermResponseOSC autocmd

File Changes

(4 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975@github.com>

Foxe Chen

unread,
Aug 12, 2025, 5:06:01 AMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/b1ffdfc59d8c093edf4eacb451d18c4e53b1938d/after/3ef914d0ed13bc3b2f56fa80d5dabb39c883bf52@github.com>

Foxe Chen

unread,
Aug 12, 2025, 5:20:15 AMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/3ef914d0ed13bc3b2f56fa80d5dabb39c883bf52/after/6eb2b4dd39880c8999e07e241e9d5d58d3452c34@github.com>

Foxe Chen

unread,
Aug 12, 2025, 5:31:09 AMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/6eb2b4dd39880c8999e07e241e9d5d58d3452c34/after/62caad65988bdbfcac0dc507749cac1f703c7301@github.com>

Foxe Chen

unread,
Aug 12, 2025, 5:46:21 AMAug 12
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

@chrisbra Is there an equivalent to gettimeofday() in Windows that should be used in the code base?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3178597992@github.com>

Foxe Chen

unread,
Aug 12, 2025, 6:12:13 AMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/62caad65988bdbfcac0dc507749cac1f703c7301/after/33c3266e5432327f28b2ac3631e8056bac007022@github.com>

Christian Brabandt

unread,
Aug 12, 2025, 3:03:37 PMAug 12
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#17975)

fixes: #14995 ?

@chrisbra Is there an equivalent to gettimeofday() in Windows that should be used in the code base?

It seems this is available
https://github.com/vim/vim/blob/397b9da29d29a96d92ebdfd9d6bf379249519fa1/src/time.c#L950-L962

Thanks for working on it. It seems you really enjoy working on not so small issues! 🙇‍♂️


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3180620143@github.com>

Foxe Chen

unread,
Aug 12, 2025, 3:30:05 PMAug 12
to vim/vim, Push

@64-bitman pushed 2 commits.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/33c3266e5432327f28b2ac3631e8056bac007022/after/7d110d365da49f4605f3d64a718e56b9bfb74d1c@github.com>

Foxe Chen

unread,
Aug 12, 2025, 3:33:45 PMAug 12
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

fixes: #14995 ?

I suppose it kind of fixes it, but we still need to add a OSC 52 Vimscript plugin. I think the best way to add that is to first implement some sort of clipboard provider functionality like Neovim.

@chrisbra Is there an equivalent to gettimeofday() in Windows that should be used in the code base?

It seems this is available

https://github.com/vim/vim/blob/397b9da29d29a96d92ebdfd9d6bf379249519fa1/src/time.c#L950-L962

I'm guessing I can make that non-static to be used elsewhere?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3180735555@github.com>

Foxe Chen

unread,
Aug 12, 2025, 3:34:54 PMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/7d110d365da49f4605f3d64a718e56b9bfb74d1c/after/ef44e6a993e46c06396558c57f38306d3612482f@github.com>

Christian Brabandt

unread,
Aug 12, 2025, 3:35:30 PMAug 12
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#17975)

I'm guessing I can make that non-static to be used elsewhere?

of course, if that makes sense.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3180741137@github.com>

Foxe Chen

unread,
Aug 12, 2025, 3:46:04 PMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/ef44e6a993e46c06396558c57f38306d3612482f/after/2bce3df4767c4ef5d0772f6d281c432ba3a74e81@github.com>

Foxe Chen

unread,
Aug 12, 2025, 3:51:42 PMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/2bce3df4767c4ef5d0772f6d281c432ba3a74e81/after/d09ffa302573bc6a2d47838eac3822eec2b57938@github.com>

Foxe Chen

unread,
Aug 12, 2025, 3:57:59 PMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/d09ffa302573bc6a2d47838eac3822eec2b57938/after/88cbd1107a3537e3ff027173b843728b1ee0cf6c@github.com>

Foxe Chen

unread,
Aug 12, 2025, 3:59:14 PMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/88cbd1107a3537e3ff027173b843728b1ee0cf6c/after/6841d296005fd19505ff06589dc1f394c9dcf27b@github.com>

Foxe Chen

unread,
Aug 12, 2025, 4:42:27 PMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/6841d296005fd19505ff06589dc1f394c9dcf27b/after/7159b88d54efcf59897bad449bb853e78e6173d4@github.com>

Foxe Chen

unread,
Aug 12, 2025, 4:53:13 PMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 7f71747 add 'osctimeoutlen' option

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/7159b88d54efcf59897bad449bb853e78e6173d4/after/7f71747c173993240090230d772c38af8172330a@github.com>

Foxe Chen

unread,
Aug 12, 2025, 5:06:17 PMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 39e4597 increase typeahead buffer size

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/7f71747c173993240090230d772c38af8172330a/after/39e4597aff602ebb8e7129c393551a890dc4f975@github.com>

Foxe Chen

unread,
Aug 12, 2025, 5:07:34 PMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

  • a48f750 increase typeahead buffer size

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/39e4597aff602ebb8e7129c393551a890dc4f975/after/a48f750f076f623c4f1bde947956d7a87321181f@github.com>

Foxe Chen

unread,
Aug 12, 2025, 5:18:41 PMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/a48f750f076f623c4f1bde947956d7a87321181f/after/efc39477168a9053972fd798daa28c533576279f@github.com>

Foxe Chen

unread,
Aug 12, 2025, 6:24:13 PMAug 12
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/efc39477168a9053972fd798daa28c533576279f/after/6baec2ee118f0f2b0beb905e3f9ea5825c67fc95@github.com>

Foxe Chen

unread,
Aug 13, 2025, 3:10:33 PMAug 13
to vim/vim, Push

@64-bitman pushed 2 commits.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/6baec2ee118f0f2b0beb905e3f9ea5825c67fc95/after/2d21775533396ec9a4a4842a53d2b20ddb06475e@github.com>

Foxe Chen

unread,
Aug 13, 2025, 3:14:27 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 6b078c9 handle terminator split over two chunks

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/2d21775533396ec9a4a4842a53d2b20ddb06475e/after/6b078c90d70ed1dc49241eaf9da0a80ba258f335@github.com>

Foxe Chen

unread,
Aug 13, 2025, 3:24:28 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 90fdc8c remove color response handling and feature flag

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/6b078c90d70ed1dc49241eaf9da0a80ba258f335/after/90fdc8c82c78d13aeb582e37966143162c73a3a0@github.com>

Foxe Chen

unread,
Aug 13, 2025, 3:32:53 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

  • f66e7ae remove color response handling and feature flag

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/90fdc8c82c78d13aeb582e37966143162c73a3a0/after/f66e7aee8959ba0671d58fdaeb6e2273f2ffdfba@github.com>

Foxe Chen

unread,
Aug 13, 2025, 6:10:42 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

  • d9a11b7 add colorresp plugin to replace c code

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/f66e7aee8959ba0671d58fdaeb6e2273f2ffdfba/after/d9a11b74fd77335241b3d853a358b050c9f85811@github.com>

Foxe Chen

unread,
Aug 13, 2025, 7:00:59 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 10ac7b2 add colorresp plugin to replace c code

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/d9a11b74fd77335241b3d853a358b050c9f85811/after/10ac7b2124d379dc3bd9fd881e4080e375cb5a31@github.com>

Foxe Chen

unread,
Aug 13, 2025, 7:05:40 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 47ae3a3 add gettimeofday for mingw

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/10ac7b2124d379dc3bd9fd881e4080e375cb5a31/after/47ae3a38e832e00de8f97ec4a63e5a53c206591f@github.com>

Foxe Chen

unread,
Aug 13, 2025, 7:08:32 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

  • db0ec6d add gettimeofday for mingw

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/47ae3a38e832e00de8f97ec4a63e5a53c206591f/after/db0ec6da8e7bfb706e01e2de6e13df1ea5e295a1@github.com>

Foxe Chen

unread,
Aug 13, 2025, 7:35:28 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

  • a5385dc add gettimeofday for mingw

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/ba6d67520877854a07c9d0963d443fac61323290/after/a5385dc3253ee2c08b11a5c311e5656e0dd93720@github.com>

Foxe Chen

unread,
Aug 13, 2025, 9:20:29 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 020fadf don't check stuff after osc identififer, add error message on timeout

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/a5385dc3253ee2c08b11a5c311e5656e0dd93720/after/020fadfece21022610817913ea89ee2673ac3a1f@github.com>

Foxe Chen

unread,
Aug 13, 2025, 9:42:27 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/020fadfece21022610817913ea89ee2673ac3a1f/after/ace1820db6331e9eb7b15a680b56c1dd6f14a19b@github.com>

Foxe Chen

unread,
Aug 13, 2025, 9:48:40 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/ace1820db6331e9eb7b15a680b56c1dd6f14a19b/after/44547a5dbf87040eb919eda74560a1c6bbe0a9cd@github.com>

Foxe Chen

unread,
Aug 13, 2025, 9:49:39 PMAug 13
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

I think this is ready for review


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3186423835@github.com>

Foxe Chen

unread,
Aug 13, 2025, 9:52:17 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

  • e047b0a add TermResponseOSC autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/7f4fba8f9707defed1765d4e02348bfd1726f1d0/after/e047b0a296640b112226fb7212bc99cf2ddc340d@github.com>

Foxe Chen

unread,
Aug 13, 2025, 9:52:28 PMAug 13
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 1dd6cac add TermResponseOSC autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/e047b0a296640b112226fb7212bc99cf2ddc340d/after/1dd6cacfb6c32450a80b2bba5b6ab1cb1a16d246@github.com>

Christian Brabandt

unread,
Aug 14, 2025, 3:49:52 PMAug 14
to vim/vim, Subscribed

@chrisbra commented on this pull request.

Thanks. Can you please also update $VIMRUNTIME/optwin.vim and regenerate the vim syntax script? cd runtime/syntax/generator && make.

Also I think we should document the new plugin colorresp.vim somewhere.

I am also wondering if not using the autocommand TermResponseALL with <amatch> set to e.g. osc would be better and backwards compatible?


In src/testdir/test_termcodes.vim:

> @@ -2803,4 +2735,21 @@ func Test_xterm_direct_no_termguicolors()
   close
 endfunc
 
+" Test if OSC terminal responses are captured correctly
+func Test_term_response_osc()
+  if !has("termresponseosc")
⬇️ Suggested change
-  if !has("termresponseosc")
+  CheckFeature termresponseosc

In src/evalvars.c:

> @@ -141,8 +141,8 @@ static struct vimvar
     {VV_NAME("t_blob",		 VAR_NUMBER), NULL, VV_RO},
     {VV_NAME("t_class",		 VAR_NUMBER), NULL, VV_RO},
     {VV_NAME("t_object",	 VAR_NUMBER), NULL, VV_RO},
-    {VV_NAME("termrfgresp",	 VAR_STRING), NULL, VV_RO},
-    {VV_NAME("termrbgresp",	 VAR_STRING), NULL, VV_RO},
+    {VV_NAME("termrfgresp",	 VAR_STRING), NULL, 0},
+    {VV_NAME("termrbgresp",	 VAR_STRING), NULL, 0},

why those changes? That looks unrelated to the OSC autocommand


In runtime/doc/autocmd.txt:

>  				<amatch> will be set to any of:
 				    "version",
 				    "cursorblink",
 				    "cursorshape",
-				    "background",
-				    "foreground",

What is the thing with Foreground and Background? It won't no longer be handled as part of the TermResponseAll auto command? That would be a backwards incompatible change. Hm, it seems to be handled as part of the new TermResponseOSC autocommand now, hmm...


In runtime/doc/autocmd.txt:

>  				    "ambiguouswidth"
 				Note that this event may be triggered halfway
 				executing another event, especially if file I/O,
 				a shell command or anything else that takes time
+				is involved.
+							*TermResponseOSC*
+TermResponseOSC
+				After a response was received from the
+				terminal from a previous OSC command that was
+				sent. The value of |v:termosc| will be set to
+				the response data. The OSC response must have
+				a terminator (see |v:termosc|), or Vim will
+				timeout after 'osctimeoutlen' milliseconds
+				waiting for one. To see how this event can be
+				used, look at the colorresp.vim plugin
+				included with Vim.
⬇️ Suggested change
-				included with Vim.
+				included with Vim.
+				Note:  TermResponseOSC will also be triggered for requested terminal foreground and background color |v:termrbgresp| |v:termrfgresp|.

Something like this to note that this now handles the terminal request colors?


In src/errors.h:

> @@ -3782,3 +3782,5 @@ EXTERN char e_duplicate_type_var_name_str[]
 EXTERN char e_diff_anchors_with_hidden_windows[]
 	INIT(= N_("E1562: Diff anchors cannot be used with hidden diff windows"));
 #endif
+EXTERN char e_osc_response_timed_out[]
+	INIT(= N_("E1563: OSC command response timed out: %.*s"));

can you please regenerate vim.pot in the po directory?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3121873990@github.com>

Copilot

unread,
Aug 14, 2025, 3:51:46 PMAug 14
to vim/vim, Subscribed

@Copilot commented on this pull request.

Pull Request Overview

This PR adds support for a new TermResponseOSC autocommand event and introduces the v:termosc vim variable to capture OSC (Operating System Command) responses from terminals. This enables handling of OSC 52 commands and other terminal responses. The implementation moves the existing C-based terminal foreground/background color response handling to a VimScript plugin (colorresp.vim) that uses the new OSC infrastructure.

Key changes:

  • Introduces EVENT_TERMRESPONSEOSC autocommand and VV_TERMOSC variable for OSC response handling
  • Replaces hardcoded color response parsing with generic OSC response capture mechanism
  • Adds osctimeoutlen option to control OSC response timeout behavior

Reviewed Changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/vim.h Adds new autocommand event and vim variable constants
src/term.c Replaces color-specific OSC handling with generic OSC response processing
src/structs.h Defines oscstate_T structure for OSC response state management
src/evalvars.c Implements new vim variable and updates existing color response variables
src/option.c Adds validation for new osctimeoutlen option
runtime/plugin/colorresp.vim New VimScript plugin for terminal color response handling
src/testdir/ Updates tests to reflect the new OSC handling approach

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.


In src/structs.h:

> @@ -1290,6 +1290,19 @@ typedef struct
 #endif
 } tasave_T;
 
+// Holds state for current OSC response.
+typedef struct
+{
+    int		    processing;	// If we are in the middle of an OSC response
+    char_u	    start_char;	// First char in the OSC response
+    garray_T	    buf;	// Buffer holding the OSC response, to be
+				// placed in the "v:vimosc" vim var.

The comment has a typo: 'vimosc' should be 'termosc' to match the actual variable name v:termosc.

⬇️ Suggested change
-				// placed in the "v:vimosc" vim var.
+				// placed in the "v:termosc" vim var.

In runtime/doc/eval.txt:

> @@ -2911,6 +2910,15 @@ v:termu7resp	The escape sequence returned by the terminal for the |t_u7|
 		this option is set, the TermResponseAll autocommand event is
 		fired, with <amatch> set to "ambiguouswidth".
 
+						*v:termosc*
+v:termosc	The data of the most recent OSC response received from the
+		terminal, without including the OSC identifier (<Esc>] or
+		character <0x9d>) and the OSC terminator, which can either be
+		a string terminator character <0x9c>, <Esc>\, or a bell
+		character.
+		When this option is set, the |TermResponseOSC| autocoomand event

There's a typo: 'autocoomand' should be 'autocommand'.

⬇️ Suggested change
-		When this option is set, the |TermResponseOSC| autocoomand event
+		When this option is set, the |TermResponseOSC| autocommand event

In runtime/plugin/colorresp.vim:

> @@ -0,0 +1,41 @@
+vim9script
+
+# Vim plugin for setting the and background and foreground colours depending on

There's a grammatical error: 'setting the and background' should be 'setting the background'.

⬇️ Suggested change
-# Vim plugin for setting the and background and foreground colours depending on
+# Vim plugin for setting the background and foreground colours depending on

In src/time.c:

> @@ -127,6 +127,20 @@ get_ctime(time_t thetime, int add_newline)
     return buf;
 }
 
+#if defined(MSWIN) || defined(__MINGW32__)
+/*
+ * Windows doesn't have gettimeofday(), although it does have struct timeval.
+ */
+    int
+gettimeofday(struct timeval *tv, char *dummy UNUSED)

The gettimeofday function is moved to global scope but lacks a header declaration. This could cause compilation warnings or errors when the function is used elsewhere.


In src/term.c:

> -			     || argp[2] != ';'))
-	i = 0; // no match
+    if (!osc_state.processing)
+    {
+	// Check if it is a valid OSC sequence, and consume it. OSC format
+	// consists of:
+	// <idenfitifer><data><terminator>
+	// <identifier> is either <Esc>] or an OSC character
+	// <terminator> can be '\007', <Esc>\ or STERM.
+	cur = 1 + (tp[0] == ESC);
+
+	if (len < cur + 1 + (tp[0] != OSC)) // Include terminator as well
+	    return FAIL;
+
+	// The whole OSC response may be larger than the typeahead buffer.
+	// To handle this, keep reading data in and out of the typahead

There's a typo: 'typahead' should be 'typeahead'.

⬇️ Suggested change
-	// To handle this, keep reading data in and out of the typahead
+	// To handle this, keep reading data in and out of the typeahead

In src/term.c:

>      else
-	for (i = j; i < len; ++i)
-	    if (tp[i] == '\007' || (tp[0] == OSC ? tp[i] == STERM
-			: (tp[i] == ESC && i + 1 < len && tp[i + 1] == '\\')))
-	    {
-		int is_bg = argp[1] == '1';
-		int is_4digit = i - j >= 21 && tp[j + 11] == '/'
-						  && tp[j + 16] == '/';
+	last_char = ((char_u *)osc_state.buf.ga_data)[osc_state.buf.ga_len - 1];
+
+    key_name[0] = (int)KS_EXTRA;
+    key_name[1] = (int)KE_IGNORE;
+
+    // Read data and append to buffer. If we reach a terminator, then
+    // finally set the vim var.
+    for (int i = cur; i < len; i++)

[nitpick] Variable declaration inside for loop may not be compatible with older C standards. Consider declaring 'i' at the beginning of the function for better compatibility.

⬇️ Suggested change
-    for (int i = cur; i < len; i++)
+    for (i = cur; i < len; i++)

In runtime/plugin/colorresp.vim:

> +  finish
+endif
+g:loaded_colorresp = 1
+
+augroup ColorResp
+  au!
+  au TermResponseOSC * {
+    var parts: list<string> = matchlist(v:termosc, '\(\d\+\);rgb:\(\w\+\)/\(\w\+\)/\(\w\+\)')
+    if len(parts) >= 5
+      var type: string = parts[1]
+      var rval: number = str2nr(parts[2][: 1], 16)
+      var gval: number = str2nr(parts[3][: 1], 16)
+      var bval: number = str2nr(parts[4][: 1], 16)
+
+      if type == '11'
+          var new_bg_val: string = (3 * char2nr('6') < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"

The magic number '6' and the formula for determining light/dark background is unclear. Consider adding a comment explaining the logic or extracting this into a named constant.

⬇️ Suggested change
-          var new_bg_val: string = (3 * char2nr('6') < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"
+          # Determine if the background color is "light" or "dark" by comparing the sum of the first hex digit of each RGB component
+          # to a threshold. 'char2nr("6")' is used as an approximate midpoint for a single hex digit (0-F), so 3 * char2nr("6") is the threshold.
+          const RGB_LIGHTNESS_THRESHOLD = 3 * char2nr('6')
+          var new_bg_val: string = (RGB_LIGHTNESS_THRESHOLD < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3121928680@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:00:58 PMAug 14
to vim/vim, Subscribed

@64-bitman commented on this pull request.


In src/evalvars.c:

> @@ -141,8 +141,8 @@ static struct vimvar
     {VV_NAME("t_blob",		 VAR_NUMBER), NULL, VV_RO},
     {VV_NAME("t_class",		 VAR_NUMBER), NULL, VV_RO},
     {VV_NAME("t_object",	 VAR_NUMBER), NULL, VV_RO},
-    {VV_NAME("termrfgresp",	 VAR_STRING), NULL, VV_RO},
-    {VV_NAME("termrbgresp",	 VAR_STRING), NULL, VV_RO},
+    {VV_NAME("termrfgresp",	 VAR_STRING), NULL, 0},
+    {VV_NAME("termrbgresp",	 VAR_STRING), NULL, 0},

I made them read writable so that the colorresp.vim plugin can set them for backwards compatibility


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3121952039@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:06:25 PMAug 14
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 0e175c3 add TermResponseOSC autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/ec3c190f74fba9f2a152728e177eb8e7402521f6/after/0e175c3f0d8b4ade45274f0bba0fd38691375ed8@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:08:18 PMAug 14
to vim/vim, Subscribed

@64-bitman commented on this pull request.


In runtime/doc/autocmd.txt:

>  				<amatch> will be set to any of:
 				    "version",
 				    "cursorblink",
 				    "cursorshape",
-				    "background",
-				    "foreground",

there was originally a handle_osc() function that specifically handled OSC responses related to terminal foreground/background colour detection. Now that has been moved to Vimscript. Maybe the colorresp.vim plugin can use doautocmd to emit a TermResponseAll event for backwards compatibility?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3121977635@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:10:38 PMAug 14
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 17d07a3 add TermResponseOSC autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/0e175c3f0d8b4ade45274f0bba0fd38691375ed8/after/17d07a33d365d0810d2dc54860600138890af34a@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:12:13 PMAug 14
to vim/vim, Subscribed

@64-bitman commented on this pull request.


In runtime/doc/autocmd.txt:

>  				    "ambiguouswidth"
 				Note that this event may be triggered halfway
 				executing another event, especially if file I/O,
 				a shell command or anything else that takes time
+				is involved.
+							*TermResponseOSC*
+TermResponseOSC
+				After a response was received from the
+				terminal from a previous OSC command that was
+				sent. The value of |v:termosc| will be set to
+				the response data. The OSC response must have
+				a terminator (see |v:termosc|), or Vim will
+				timeout after 'osctimeoutlen' milliseconds
+				waiting for one. To see how this event can be
+				used, look at the colorresp.vim plugin
+				included with Vim.

This PR treats the terminal colour responses like any other OSC response. Its just that the colorresp.vim plugin does the work that the original c code did


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3121993338@github.com>

Christian Brabandt

unread,
Aug 14, 2025, 4:12:40 PMAug 14
to vim/vim, Subscribed

@chrisbra commented on this pull request.


In runtime/doc/autocmd.txt:

>  				<amatch> will be set to any of:
 				    "version",
 				    "cursorblink",
 				    "cursorshape",
-				    "background",
-				    "foreground",

yeah, that should work I guess.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3121995532@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:16:54 PMAug 14
to vim/vim, Subscribed

@64-bitman commented on this pull request.


In runtime/doc/autocmd.txt:

>  				<amatch> will be set to any of:
 				    "version",
 				    "cursorblink",
 				    "cursorshape",
-				    "background",
-				    "foreground",

Ok I did that and it seems to work, so I guess this is resolved?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3122006193@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:17:13 PMAug 14
to vim/vim, Push

@64-bitman pushed 1 commit.

  • f306fe9 add TermResponseOSC autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/17d07a33d365d0810d2dc54860600138890af34a/after/f306fe9a5e5d2e1b0fcf67fa00a60bd282f12e08@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:19:40 PMAug 14
to vim/vim, Subscribed

@64-bitman commented on this pull request.


In runtime/plugin/colorresp.vim:

> +  finish
+endif
+g:loaded_colorresp = 1
+
+augroup ColorResp
+  au!
+  au TermResponseOSC * {
+    var parts: list<string> = matchlist(v:termosc, '\(\d\+\);rgb:\(\w\+\)/\(\w\+\)/\(\w\+\)')
+    if len(parts) >= 5
+      var type: string = parts[1]
+      var rval: number = str2nr(parts[2][: 1], 16)
+      var gval: number = str2nr(parts[3][: 1], 16)
+      var bval: number = str2nr(parts[4][: 1], 16)
+
+      if type == '11'
+          var new_bg_val: string = (3 * char2nr('6') < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"

To be honest I don't know how this works really, I just copied it from the original C code and translated to Vimscript and it passes the tests so I guess it works


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3122012688@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:20:37 PMAug 14
to vim/vim, Push

@64-bitman pushed 1 commit.

  • f58cddf add TermResponseOSC autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/f306fe9a5e5d2e1b0fcf67fa00a60bd282f12e08/after/f58cddfaf85f3dea69b92069277b0c8428610ff9@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:21:09 PMAug 14
to vim/vim, Subscribed

@64-bitman commented on this pull request.


In src/time.c:

> @@ -127,6 +127,20 @@ get_ctime(time_t thetime, int add_newline)
     return buf;
 }
 
+#if defined(MSWIN) || defined(__MINGW32__)
+/*
+ * Windows doesn't have gettimeofday(), although it does have struct timeval.
+ */
+    int
+gettimeofday(struct timeval *tv, char *dummy UNUSED)

Copilot doesn't know its in the time.pro file?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3122016031@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:27:19 PMAug 14
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 777a0c6 add TermResponseOSC autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/f58cddfaf85f3dea69b92069277b0c8428610ff9/after/777a0c63217108bafa0295b14b86bce044a86364@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:28:22 PMAug 14
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 8e01f1e add TermResponseOSC autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/777a0c63217108bafa0295b14b86bce044a86364/after/8e01f1e6fb870243f52198942f4b3c3b2681b316@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:33:09 PMAug 14
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

Thanks. Can you please also update $VIMRUNTIME/optwin.vim and regenerate the vim syntax script? cd runtime/syntax/generator && make.

Done

Also I think we should document the new plugin colorresp.vim somewhere.

I'm not sure where to document it though. This plugin is similar to the rrhelper.vim plugin (which doesn't have documentation), so I'm not sure if documentation is necessary

I am also wondering if not using the autocommand TermResponseALL with <amatch> set to e.g. osc would be better and backwards compatible?

I think its better to have separate autocommand TermResponseOSC, since TermResponseAll seems to be for specific terminal responses, while TermResponseOSC is for OSC responses in general. Considering that there was no "osc' value for in the first place, I don't think this would affect backwards compatbility


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3189796050@github.com>

Christian Brabandt

unread,
Aug 14, 2025, 4:52:09 PMAug 14
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#17975)

Thanks. Can you please also update $VIMRUNTIME/optwin.vim and regenerate the vim syntax script? cd runtime/syntax/generator && make.

Done

Also I think we should document the new plugin colorresp.vim somewhere.

I'm not sure where to document it though. This plugin is similar to the rrhelper.vim plugin (which doesn't have documentation), so I'm not sure if documentation is necessary

Yeah, also not sure. Hm, let's then just make it explicit in the help, like $VIMRUNTIME/plugin/colorresp.vim so gf on it works.

I am also wondering if not using the autocommand TermResponseALL with <amatch> set to e.g. osc would be better and backwards compatible?

I think its better to have separate autocommand TermResponseOSC, since TermResponseAll seems to be for specific terminal responses, while TermResponseOSC is for OSC responses in general. Considering that there was no "osc' value for in the first place, I don't think this would affect backwards compatbility

Okay


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3189839285@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:58:53 PMAug 14
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

Yeah, also not sure. Hm, let's then just make it explicit in the help, like $VIMRUNTIME/plugin/colorresp.vim so gf on it works.

I'm not sure what you mean, can you elaborate?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3189854299@github.com>

Foxe Chen

unread,
Aug 14, 2025, 4:59:33 PMAug 14
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 1057db8 add TermResponseOSC autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/8e01f1e6fb870243f52198942f4b3c3b2681b316/after/1057db805c036acbeaf402f431c2e5e8ca09bd96@github.com>

Christian Brabandt

unread,
Aug 14, 2025, 5:11:22 PMAug 14
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#17975)

Yeah, also not sure. Hm, let's then just make it explicit in the help, like $VIMRUNTIME/plugin/colorresp.vim so gf on it works.

I'm not sure what you mean, can you elaborate?

Something like this (slightly reworded using ChatGPT):

TermResponseOSC
        After a response is received from the terminal for a previously sent
        OSC (Operating System Command). The response data is stored in
        |v:termosc|.  The terminal response must include a terminator
        (see |v:termosc|); otherwise, Vim will wait up to
        'osctimeoutlen' milliseconds and then timeout.

        To see an example of using this event, see
        $VIMRUNTIME/plugin/colorresp.vim.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3189883664@github.com>

Foxe Chen

unread,
Aug 14, 2025, 5:40:43 PMAug 14
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 89fe260 add TermResponseOSC autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/1057db805c036acbeaf402f431c2e5e8ca09bd96/after/89fe260a11fc1de405eda453c2a5fb76801a19b6@github.com>

Foxe Chen

unread,
Aug 14, 2025, 5:41:27 PMAug 14
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

Something like this (slightly reworded using ChatGPT):

TermResponseOSC
        After a response is received from the terminal for a previously sent
        OSC (Operating System Command). The response data is stored in
        |v:termosc|.  The terminal response must include a terminator
        (see |v:termosc|); otherwise, Vim will wait up to
        'osctimeoutlen' milliseconds and then timeout.

        To see an example of using this event, see
        $VIMRUNTIME/plugin/colorresp.vim.

Thanks, changed it


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3189943745@github.com>

Phạm Bình An

unread,
Aug 14, 2025, 6:02:23 PMAug 14
to vim/vim, Subscribed
brianhuster left a comment (vim/vim#17975)

Given that there is already TermResponseAll, should this PR extend it, with being set to osc for example?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3189981038@github.com>

Foxe Chen

unread,
Aug 14, 2025, 6:20:44 PMAug 14
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

I think its better to have separate autocommand TermResponseOSC, since TermResponseAll seems to be for specific terminal responses, while TermResponseOSC is for OSC responses in general. Considering that there was no "osc' value for in the first place, I don't think this would affect backwards compatbility


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3190021899@github.com>

Foxe Chen

unread,
Aug 14, 2025, 6:54:56 PMAug 14
to vim/vim, Push

@64-bitman pushed 1 commit.

  • dcf9b6a add TermResponseOSC autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/89fe260a11fc1de405eda453c2a5fb76801a19b6/after/dcf9b6a11c9713981e11254820e0f8dcebf627a3@github.com>

Foxe Chen

unread,
Aug 15, 2025, 8:46:01 AMAug 15
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

@chrisbra Actually, I've decided to use TermResponseAll with <amatch> set to osc, It will make more sense if we start handling more types of terminal sequence responses


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3191420674@github.com>

Foxe Chen

unread,
Aug 15, 2025, 8:54:13 AMAug 15
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 1c28f45 add new osc <match> value toTermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/9af265acf27a6e7d5c8f4ff222eb8267d1d808d1/after/1c28f454603b8ad9b22a4f58d9efcb80c142c253@github.com>

Foxe Chen

unread,
Aug 15, 2025, 8:57:11 AMAug 15
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 3859357 add new osc <match> value toTermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/1c28f454603b8ad9b22a4f58d9efcb80c142c253/after/3859357c5e6ee9843e06233112a5a63240b7ed2e@github.com>

Foxe Chen

unread,
Aug 15, 2025, 10:01:22 AMAug 15
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 441cb3f add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/3859357c5e6ee9843e06233112a5a63240b7ed2e/after/441cb3f5643727150be101152ae4478bb0116801@github.com>

Foxe Chen

unread,
Aug 15, 2025, 2:36:08 PMAug 15
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 17bd662 add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/441cb3f5643727150be101152ae4478bb0116801/after/17bd6629640e120c8620cda07b7bc62cc2c42cb2@github.com>

Foxe Chen

unread,
Aug 15, 2025, 9:26:24 PMAug 15
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 5d5cd64 add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/17bd6629640e120c8620cda07b7bc62cc2c42cb2/after/5d5cd649f5c255015a5a5f7c5783f2a809e26186@github.com>

Foxe Chen

unread,
Aug 16, 2025, 12:25:34 AMAug 16
to vim/vim, Push

@64-bitman pushed 1 commit.

  • b84a16b add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/5d5cd649f5c255015a5a5f7c5783f2a809e26186/after/b84a16bb03e6945991ff6b0c64f8dd84ff6680a8@github.com>

Foxe Chen

unread,
Aug 16, 2025, 12:28:19 AMAug 16
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 1877b4b add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/b84a16bb03e6945991ff6b0c64f8dd84ff6680a8/after/1877b4be497939edc7a5181b9de38da9214f6f03@github.com>

Foxe Chen

unread,
Aug 16, 2025, 12:37:32 AMAug 16
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 3e0a43d add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/1877b4be497939edc7a5181b9de38da9214f6f03/after/3e0a43d809c1e92322489ae089bfb36dbf4e7d96@github.com>

Foxe Chen

unread,
Aug 16, 2025, 2:24:00 PMAug 16
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 203cd3d add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/3e0a43d809c1e92322489ae089bfb36dbf4e7d96/after/203cd3dc6139fb7d85e549736fbf0519d41a2b8f@github.com>

Foxe Chen

unread,
Aug 16, 2025, 2:39:42 PMAug 16
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 3e6a650 add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/203cd3dc6139fb7d85e549736fbf0519d41a2b8f/after/3e6a650ca437e4d7264273204c3cc7c5e05f180c@github.com>

Foxe Chen

unread,
Aug 16, 2025, 3:09:54 PMAug 16
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

I think this is ready


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3193853998@github.com>

Christian Brabandt

unread,
Aug 17, 2025, 4:24:51 PMAug 17
to vim/vim, Subscribed

@chrisbra commented on this pull request.


In runtime/doc/autocmd.txt:

>  				    "ambiguouswidth"
+				    "osc"

Note: Traditionally, TermResponseAll was also used for "foreground" and "background" patterns. These are now handled as part of the "osc" value. For backwards compatibility, however, the colorresp.vim plugin will handle "osc" events and emit TermResponseAll autocommand events when it encounters "foreground" and "background" values.


In runtime/doc/eval.txt:

> @@ -2911,6 +2910,12 @@ v:termu7resp	The escape sequence returned by the terminal for the |t_u7|
 		this option is set, the TermResponseAll autocommand event is
 		fired, with <amatch> set to "ambiguouswidth".
 
+						*v:termosc*
+v:termosc	The escape sequence of the most recent OSC response received
+		from the terminal, When this option is set, the
+		|TermResponseAll| autocommand event is fired, with <amatch>
+		set to "osc".

Also used to handle "foreground" and "background" terminal responses.


In runtime/doc/eval.txt:

> @@ -2911,6 +2910,12 @@ v:termu7resp	The escape sequence returned by the terminal for the |t_u7|
 		this option is set, the TermResponseAll autocommand event is
 		fired, with <amatch> set to "ambiguouswidth".
 
+						*v:termosc*
+v:termosc	The escape sequence of the most recent OSC response received
+		from the terminal, When this option is set, the
⬇️ Suggested change
-		from the terminal, When this option is set, the
+		from the terminal.  When this option is set, the

In runtime/plugin/colorresp.vim:

> @@ -0,0 +1,48 @@
+vim9script

The name colorresp is a bit obscure. Should we call it termosc.vim ?


In runtime/plugin/colorresp.vim:

> +  finish
+endif
+g:loaded_colorresp = 1
+
+augroup ColorResp
+  au!
+  au TermResponseOSC * {
+    var parts: list<string> = matchlist(v:termosc, '\(\d\+\);rgb:\(\w\+\)/\(\w\+\)/\(\w\+\)')
+    if len(parts) >= 5
+      var type: string = parts[1]
+      var rval: number = str2nr(parts[2][: 1], 16)
+      var gval: number = str2nr(parts[3][: 1], 16)
+      var bval: number = str2nr(parts[4][: 1], 16)
+
+      if type == '11'
+          var new_bg_val: string = (3 * char2nr('6') < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"

So let's add a comment like this:
" Detect light or dark background by parsing OSC 11 RGB background reply from terminal.
" Sum the RGB values roughly; if bright enough, set 'background' to 'light',
" otherwise set it to 'dark'.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3126451011@github.com>

Christian Brabandt

unread,
Aug 17, 2025, 4:26:03 PMAug 17
to vim/vim, Subscribed

@chrisbra commented on this pull request.

I have a few additional comments. What do you think?


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3126452789@github.com>

Foxe Chen

unread,
Aug 17, 2025, 4:26:47 PMAug 17
to vim/vim, Subscribed

@64-bitman commented on this pull request.


In runtime/plugin/colorresp.vim:

> @@ -0,0 +1,48 @@
+vim9script

I think that is a somewhat broad name for the usecase of the plugin. Maybe it should be colorresponse.vim?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3126452969@github.com>

Foxe Chen

unread,
Aug 17, 2025, 4:33:45 PMAug 17
to vim/vim, Subscribed

@64-bitman commented on this pull request.


In runtime/plugin/colorresp.vim:

> +  finish
+endif
+g:loaded_colorresp = 1
+
+augroup ColorResp
+  au!
+  au TermResponseOSC * {
+    var parts: list<string> = matchlist(v:termosc, '\(\d\+\);rgb:\(\w\+\)/\(\w\+\)/\(\w\+\)')
+    if len(parts) >= 5
+      var type: string = parts[1]
+      var rval: number = str2nr(parts[2][: 1], 16)
+      var gval: number = str2nr(parts[3][: 1], 16)
+      var bval: number = str2nr(parts[4][: 1], 16)
+
+      if type == '11'
+          var new_bg_val: string = (3 * char2nr('6') < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"

Okay, will do


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/review/3126454331@github.com>

Foxe Chen

unread,
Aug 17, 2025, 4:35:24 PMAug 17
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 752b426 add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/3e6a650ca437e4d7264273204c3cc7c5e05f180c/after/752b426af4adf6e137400f1c6b12454166a7f17e@github.com>

Foxe Chen

unread,
Aug 17, 2025, 5:42:59 PMAug 17
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 3c3aedc add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/752b426af4adf6e137400f1c6b12454166a7f17e/after/3c3aedc05d4bcd8dab257fb5e74b720c32adb34e@github.com>

Foxe Chen

unread,
Aug 18, 2025, 3:57:57 PMAug 18
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 38fc3df add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/3c3aedc05d4bcd8dab257fb5e74b720c32adb34e/after/38fc3dfa902434973294d4db84d015f4d73084d3@github.com>

Foxe Chen

unread,
Aug 20, 2025, 3:12:43 PMAug 20
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

I think this is ready


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3207715414@github.com>

Christian Brabandt

unread,
Aug 23, 2025, 12:15:27 PMAug 23
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#17975)

can you please rebase?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3217146455@github.com>

Foxe Chen

unread,
Aug 23, 2025, 2:46:28 PMAug 23
to vim/vim, Push

@64-bitman pushed 1 commit.

  • db22467 add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/38fc3dfa902434973294d4db84d015f4d73084d3/after/db224674ace147019ac4083eec8c09b6e482649f@github.com>

Foxe Chen

unread,
Aug 23, 2025, 2:46:53 PMAug 23
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

can you please rebase?

Done


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3217253027@github.com>

Foxe Chen

unread,
Aug 27, 2025, 8:54:29 AMAug 27
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 51da996 add new osc <match> value to TermResponseAll autocommand event

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/before/db224674ace147019ac4083eec8c09b6e482649f/after/51da99605a30bc01afa6e985b19fb663533430b2@github.com>

Christian Brabandt

unread,
Aug 27, 2025, 3:19:07 PMAug 27
to vim/vim, Subscribed

Closed #17975 via 1f51bbc.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/issue_event/19376002203@github.com>

Christian Brabandt

unread,
Aug 27, 2025, 3:19:09 PMAug 27
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#17975)

thanks


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3229462310@github.com>

Linwei

unread,
Sep 9, 2025, 2:57:52 AMSep 9
to vim/vim, Subscribed
skywind3000 left a comment (vim/vim#17975)

@64-bitman this PR breaks Windows Terminal, could you please take a look at: #18251


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3269151877@github.com>

Foxe Chen

unread,
Sep 9, 2025, 4:14:21 AMSep 9
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

@64-bitman this PR breaks Windows Terminal, could you please take a look at: #18251

I believe #18149 fixed this, can you use the newest version of vim and try again?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3269452886@github.com>

Linwei

unread,
Sep 9, 2025, 9:17:29 AMSep 9
to vim/vim, Subscribed
skywind3000 left a comment (vim/vim#17975)

I believe #18149 fixed this, can you use the newest version of vim and try again?

It didn't fix at all. Yesterday I updated my vim from 9.1.1640 to 9.1.1740 and found this issue, then located the problem was introduced in this PR.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3270706042@github.com>

Foxe Chen

unread,
Sep 9, 2025, 10:26:48 AMSep 9
to vim/vim, Subscribed
64-bitman left a comment (vim/vim#17975)

I believe #18149 fixed this, can you use the newest version of vim and try again?

It didn't fix at all. Yesterday I updated my vim from 9.1.1640 to 9.1.1740 and found this issue, then located the problem was introduced in this PR.

Can you add let g:loaded_colorresp = 1 to your vimrc and see if that fixes it?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3270985838@github.com>

Linwei

unread,
Sep 9, 2025, 11:41:07 AMSep 9
to vim/vim, Subscribed
skywind3000 left a comment (vim/vim#17975)

I believe #18149 fixed this, can you use the newest version of vim and try again?

It didn't fix at all. Yesterday I updated my vim from 9.1.1640 to 9.1.1740 and found this issue, then located the problem was introduced in this PR.

Can you add let g:loaded_colorresp = 1 to your vimrc and see if that fixes it?

Your solution works. adding let g:loaded_colorresp = 1 did fix the problem.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17975/c3271280882@github.com>

Reply all
Reply to author
Forward
0 new messages