[vim/vim] gui: Implement 'guidarkmode' (PR #18029)

55 views
Skip to first unread message

LemonBoy

unread,
Aug 17, 2025, 4:59:13 AMAug 17
to vim/vim, Subscribed

Allow gvim to follow the system dark mode and allow the user to override this choice.

The option is already being honored by the GTK UI when 'guioptions' cointains 'd', but this new option gives more freedom to implement different strategies (e.g. the use_bg one that follows the 'bg' value) as needed.

Closes #3922

cc @ychin as we had discussed the 'guidarkmode' behaviour quite some time ago.


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

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

Commit Summary

  • 952bcb5 gui: Implement 'guidarkmode'

File Changes

(15 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/18029@github.com>

LemonBoy

unread,
Aug 17, 2025, 5:10:48 AMAug 17
to vim/vim, Push

@LemonBoy 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/18029/before/6a48ed6fc21bab17acfae13bcf7422e31e9bdd4f/after/b8ff61d8eca524dd71bb1eaf629a0a3399d8f48c@github.com>

LemonBoy

unread,
Aug 17, 2025, 5:16:50 AMAug 17
to vim/vim, Push

@LemonBoy pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18029/before/b8ff61d8eca524dd71bb1eaf629a0a3399d8f48c/after/b7ac7f539a4c1d85040c29e049e2758e345f0f2f@github.com>

LemonBoy

unread,
Aug 17, 2025, 5:30:32 AMAug 17
to vim/vim, Push

@LemonBoy pushed 1 commit.

  • 3e34758 Fuck this shit, I'm going home

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18029/before/b7ac7f539a4c1d85040c29e049e2758e345f0f2f/after/3e347586aae78cc38a46c43b83884289be816cd2@github.com>

LemonBoy

unread,
Aug 17, 2025, 5:56:06 AMAug 17
to vim/vim, Push

@LemonBoy pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18029/before/3e347586aae78cc38a46c43b83884289be816cd2/after/931d35af22bc82d881a981a726264cbfd7939b58@github.com>

毛逸宁

unread,
Aug 17, 2025, 7:08:18 AMAug 17
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#18029)

Your contribution is great, how about add my commit in 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/18029/c3194312587@github.com>

LemonBoy

unread,
Aug 17, 2025, 11:56:47 AMAug 17
to vim/vim, Push

@LemonBoy pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18029/before/931d35af22bc82d881a981a726264cbfd7939b58/after/fe0bdadc9c1982b8ee48690025f902327a161306@github.com>

LemonBoy

unread,
Aug 17, 2025, 11:58:32 AMAug 17
to vim/vim, Subscribed
LemonBoy left a comment (vim/vim#18029)

Your contribution is great, how about add my commit in it?

Sure, why not, it looks pretty cool. You can enable it with guidarkmode=use_theme, the popup menus are currently styled using the light theme because I couldn't be arsed to implement a way to check if the GUI colors are bright or dark.

Anyways, any improvement is welcome.


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/18029/c3194473216@github.com>

Christian Brabandt

unread,
Aug 17, 2025, 1:59:23 PMAug 17
to vim/vim, Subscribed

@chrisbra commented on this pull request.


In runtime/doc/options.txt:

> @@ -4333,6 +4333,20 @@ A jump table for the options with a short description can be found at |Q_op|.
 	In its simplest form the value is just one font name.
 	See |gui-font| for the details.
 
+					*'guidarkmode'*
+'guidarkmode'		string	(default "automatic")
+			global
+			{only available when compiled with GUI enabled}
+	This option specifies whether Vim GUI elements should be drawn using a
+	dark color scheme if available.

color scheme has a very distinct meaning in Vim. Is this really a Vim color scheme or something else?


In runtime/doc/options.txt:

> @@ -4333,6 +4333,20 @@ A jump table for the options with a short description can be found at |Q_op|.
 	In its simplest form the value is just one font name.
 	See |gui-font| for the details.
 
+					*'guidarkmode'*
+'guidarkmode'		string	(default "automatic")
+			global
+			{only available when compiled with GUI enabled}
+	This option specifies whether Vim GUI elements should be drawn using a
+	dark color scheme if available.
+	The allowed values are:
+	  automatic	Follow the current system's preference.
+	  prefer_dark	Apply the dark mode to the GUI elements.
+	  prefer_light	Apply the light mode to the GUI elements.

I don't understand that. Does prefer_dark mean, to use dark GUI mode? And prefer_light means to use light/default GUI mode?


In runtime/doc/options.txt:

> @@ -4333,6 +4333,20 @@ A jump table for the options with a short description can be found at |Q_op|.
 	In its simplest form the value is just one font name.
 	See |gui-font| for the details.
 
+					*'guidarkmode'*
+'guidarkmode'		string	(default "automatic")
+			global
+			{only available when compiled with GUI enabled}
+	This option specifies whether Vim GUI elements should be drawn using a
+	dark color scheme if available.
+	The allowed values are:
+	  automatic	Follow the current system's preference.

How is this different to go-d? Which one is preferred? This should also probably be linked here.


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/18029/review/3126420224@github.com>

毛逸宁

unread,
Aug 17, 2025, 11:19:16 PMAug 17
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#18029)

By the way, is it really need to have too many options?
I think we only need two options, one is follow the background option, one is follow the colorscheme.
TODO: Now the autocomplete of the options is still a vacancy.


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/18029/c3194973359@github.com>

毛逸宁

unread,
Aug 17, 2025, 11:46:33 PMAug 17
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#18029)

I compile the forks it seems that automatic isn't take effect at first


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/18029/c3195007100@github.com>

毛逸宁

unread,
Aug 18, 2025, 2:17:11 AMAug 18
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#18029)

Or maybe we can separate implement in windows 11 and before. And use guioptions to control whether change the colour of titlebar or not. We change the colour of titlebar with the colour of background. set these logic in gui_mch_new_colors() function.
At present, Vim's default colorscheme doesn't support set background = dark. So it's no use to set according to the OS's setting.


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/18029/c3195269480@github.com>

LemonBoy

unread,
Aug 18, 2025, 3:17:22 AMAug 18
to vim/vim, Subscribed

@LemonBoy commented on this pull request.


In runtime/doc/options.txt:

> @@ -4333,6 +4333,20 @@ A jump table for the options with a short description can be found at |Q_op|.
 	In its simplest form the value is just one font name.
 	See |gui-font| for the details.
 
+					*'guidarkmode'*
+'guidarkmode'		string	(default "automatic")
+			global
+			{only available when compiled with GUI enabled}
+	This option specifies whether Vim GUI elements should be drawn using a
+	dark color scheme if available.

Nope, it's just the system dark color palette/implementation/whatever.


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/18029/review/3127073392@github.com>

LemonBoy

unread,
Aug 18, 2025, 3:17:40 AMAug 18
to vim/vim, Subscribed

@LemonBoy commented on this pull request.


In runtime/doc/options.txt:

> @@ -4333,6 +4333,20 @@ A jump table for the options with a short description can be found at |Q_op|.
 	In its simplest form the value is just one font name.
 	See |gui-font| for the details.
 
+					*'guidarkmode'*
+'guidarkmode'		string	(default "automatic")
+			global
+			{only available when compiled with GUI enabled}
+	This option specifies whether Vim GUI elements should be drawn using a
+	dark color scheme if available.
+	The allowed values are:
+	  automatic	Follow the current system's preference.
+	  prefer_dark	Apply the dark mode to the GUI elements.
+	  prefer_light	Apply the light mode to the GUI elements.

Yep.


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/18029/review/3127074710@github.com>

LemonBoy

unread,
Aug 18, 2025, 3:18:52 AMAug 18
to vim/vim, Subscribed

@LemonBoy commented on this pull request.


In runtime/doc/options.txt:

> @@ -4333,6 +4333,20 @@ A jump table for the options with a short description can be found at |Q_op|.
 	In its simplest form the value is just one font name.
 	See |gui-font| for the details.
 
+					*'guidarkmode'*
+'guidarkmode'		string	(default "automatic")
+			global
+			{only available when compiled with GUI enabled}
+	This option specifies whether Vim GUI elements should be drawn using a
+	dark color scheme if available.
+	The allowed values are:
+	  automatic	Follow the current system's preference.

go-d was too limited as it was just a on/off switch, adding this setting allows for more combinations without being limited to one letter options.


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/18029/review/3127080357@github.com>

LemonBoy

unread,
Aug 18, 2025, 3:20:56 AMAug 18
to vim/vim, Subscribed
LemonBoy left a comment (vim/vim#18029)

By the way, is it really need to have too many options? I think we only need two options, one is follow the background option, one is follow the colorscheme.

Adding a way to force the dark or light mode doesn't really add a lot of code.

So it's no use to set according to the OS's setting.

That's what the automatic switch is supposed to do, follow the system preferences.


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/18029/c3195435124@github.com>

毛逸宁

unread,
Aug 18, 2025, 3:27:27 AMAug 18
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#18029)

I compile the pr's version. It seems that guidarkmode isn't work unless I reset the option manually or put it in vimrc


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/18029/c3195460312@github.com>

LemonBoy

unread,
Aug 18, 2025, 4:58:27 AMAug 18
to vim/vim, Push

@LemonBoy pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18029/before/fe0bdadc9c1982b8ee48690025f902327a161306/after/67fd314f9f97ca58eae735fc0f84b42490e2db49@github.com>

LemonBoy

unread,
Aug 18, 2025, 5:01:18 AMAug 18
to vim/vim, Subscribed
LemonBoy left a comment (vim/vim#18029)

Alright, it took me a while to remember what I did two years ago. The default is to keep the titlebar as-is, following the go-d option if present.

Regarding docs, please feel free to improve it as needed, I'm running out of bandwidth to take care of 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/18029/c3195768445@github.com>

Christian Brabandt

unread,
Aug 23, 2025, 12:16:38 PMAug 23
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#18029)

Can't we not just fix the go-d case, without adding a new option?


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/18029/c3217147160@github.com>

LemonBoy

unread,
Aug 23, 2025, 2:34:35 PMAug 23
to vim/vim, Subscribed
LemonBoy left a comment (vim/vim#18029)

Can't we not just fix the go-d case, without adding a new option?

This was already discussed in #12282, the plan was to have something more flexible and eventually something that's compatible with what MacVIM already has.


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/18029/c3217246524@github.com>

Christian Brabandt

unread,
Aug 24, 2025, 3:38:07 AMAug 24
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#18029)

Ah, I remember thanks. Let me try it out to see how well this works. @ychin any comments from your side? Would you be fine with the suggested changes?


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/18029/c3217911874@github.com>

Christian Brabandt

unread,
Aug 26, 2025, 4:46:06 PMAug 26
to vim/vim, Subscribed

@chrisbra commented on this pull request.


In src/optiondefs.h:

> @@ -1228,6 +1228,15 @@ static struct vimoption options[] =
 #else
 			    (char_u *)NULL, PV_NONE, NULL, NULL,
 			    {(char_u *)NULL, (char_u *)0L}
+#endif
+			    SCTX_INIT},
+    {"guidarkmode",  NULL,  P_STRING|P_VI_DEF|P_RCLR,
+#if defined(FEAT_GUI_DARKTHEME)
+			    (char_u *)&p_guidarkmode, PV_NONE, did_set_guidarkmode, NULL,
+			    {(char_u *)"", (char_u *)0L}

I thought the default is supposed to be automatic?


In src/optiondefs.h:

> @@ -1228,6 +1228,15 @@ static struct vimoption options[] =
 #else
 			    (char_u *)NULL, PV_NONE, NULL, NULL,
 			    {(char_u *)NULL, (char_u *)0L}
+#endif
+			    SCTX_INIT},
+    {"guidarkmode",  NULL,  P_STRING|P_VI_DEF|P_RCLR,
+#if defined(FEAT_GUI_DARKTHEME)
+			    (char_u *)&p_guidarkmode, PV_NONE, did_set_guidarkmode, NULL,

No tab completions of option values?


In runtime/doc/options.txt:

> @@ -4333,6 +4333,20 @@ A jump table for the options with a short description can be found at |Q_op|.
 	In its simplest form the value is just one font name.
 	See |gui-font| for the details.
 
+					*'guidarkmode'*
+'guidarkmode'		string	(default "automatic")
+			global
+			{only available when compiled with GUI enabled}
+	This option specifies whether Vim GUI elements should be drawn using a
+	dark color scheme if available.
+	The allowed values are:
+	  automatic	Follow the current system's preference.
+	  prefer_dark	Apply the dark mode to the GUI elements.
+	  prefer_light	Apply the light mode to the GUI elements.
+	  use_bg	Follow the value of Vim's |background| option.
+	  use_theme	Use the theme foreground and background colors to style the
+			titlebar.

So I tried it out. Automatic is nice, although this is not the default, as what is claimed. Also we cannot tab complete the available options. But it seems to be only applied to the title bar? The menu bar and the toolbar seem to stay in light mode.
Then I don't know what prefer_dark and prefer_light are supposed to be doing. Both options don't seem to make a difference at all, similar with use_theme .

Then I was wondering, does it make sense to combine those values? Perhaps I want to switch dark mode automatic on but also want to set/unset it when issuing :set bg ?


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/18029/review/3157234991@github.com>

LemonBoy

unread,
Aug 27, 2025, 3:04:46 AMAug 27
to vim/vim, Subscribed

@LemonBoy commented on this pull request.


In src/optiondefs.h:

> @@ -1228,6 +1228,15 @@ static struct vimoption options[] =
 #else
 			    (char_u *)NULL, PV_NONE, NULL, NULL,
 			    {(char_u *)NULL, (char_u *)0L}
+#endif
+			    SCTX_INIT},
+    {"guidarkmode",  NULL,  P_STRING|P_VI_DEF|P_RCLR,
+#if defined(FEAT_GUI_DARKTHEME)
+			    (char_u *)&p_guidarkmode, PV_NONE, did_set_guidarkmode, NULL,
+			    {(char_u *)"", (char_u *)0L}

Eh. It's a bit of a mess right now, if nothing is specified here we follow the d spec in guioptions, that's why I kept the empty string as default.


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/18029/review/3158594495@github.com>

LemonBoy

unread,
Aug 27, 2025, 3:05:02 AMAug 27
to vim/vim, Subscribed

@LemonBoy commented on this pull request.


In src/optiondefs.h:

> @@ -1228,6 +1228,15 @@ static struct vimoption options[] =
 #else
 			    (char_u *)NULL, PV_NONE, NULL, NULL,
 			    {(char_u *)NULL, (char_u *)0L}
+#endif
+			    SCTX_INIT},
+    {"guidarkmode",  NULL,  P_STRING|P_VI_DEF|P_RCLR,
+#if defined(FEAT_GUI_DARKTHEME)
+			    (char_u *)&p_guidarkmode, PV_NONE, did_set_guidarkmode, NULL,

Good catch, will fix that.


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/18029/review/3158595113@github.com>

LemonBoy

unread,
Aug 27, 2025, 3:10:20 AMAug 27
to vim/vim, Subscribed

@LemonBoy commented on this pull request.


In runtime/doc/options.txt:

> @@ -4333,6 +4333,20 @@ A jump table for the options with a short description can be found at |Q_op|.
 	In its simplest form the value is just one font name.
 	See |gui-font| for the details.
 
+					*'guidarkmode'*
+'guidarkmode'		string	(default "automatic")
+			global
+			{only available when compiled with GUI enabled}
+	This option specifies whether Vim GUI elements should be drawn using a
+	dark color scheme if available.
+	The allowed values are:
+	  automatic	Follow the current system's preference.
+	  prefer_dark	Apply the dark mode to the GUI elements.
+	  prefer_light	Apply the light mode to the GUI elements.
+	  use_bg	Follow the value of Vim's |background| option.
+	  use_theme	Use the theme foreground and background colors to style the
+			titlebar.

But it seems to be only applied to the title bar? The menu bar and the toolbar seem to stay in light mode.

Windows is to blame here, there's a way to get the toolbar and menubars to match the dark color but they're quite messy and require calling some undocumented DLL exports.

Then I don't know what prefer_dark and prefer_light are supposed to be doing. Both options don't seem to make a difference at all, similar with use_theme .

The prefer_ options force the bars to be in dark or light mode, independent of the system's configuration. use_theme makes the bar background and forground color match the guibg and guifg of the Normal group, while use_bg applies the dark or light mode according to whether the bg option is dark or light.
Suggestions to improve the docs (and/or the option names) are welcome.

Then I was wondering, does it make sense to combine those values? Perhaps I want to switch dark mode automatic on but also want to set/unset it when issuing :set bg ?

I'd avoid overcomplicating this mechanism heh


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/18029/review/3158613296@github.com>

LemonBoy

unread,
3:36 AM (7 hours ago) 3:36 AM
to vim/vim, Subscribed

Closed #18029.


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/18029/issue_event/20134088503@github.com>

LemonBoy

unread,
3:36 AM (7 hours ago) 3:36 AM
to vim/vim, Subscribed
LemonBoy left a comment (vim/vim#18029)

Well fuck me then, instead of discussing how to land this patch y'all merged (and reverted in record time) the half-assed version instead.
I have no time to deal with this bullshit,


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/18029/c3375573644@github.com>

Reply all
Reply to author
Forward
0 new messages