commit 249f305bbcddf10264835c5845035a42030d9184
parent e6fae6445445fe266b353aa4ca4a4f40ad44f0ac
Author: Rahul Yedida <rahul.yedida@pm.me>
Date: Mon, 16 Feb 2026 09:05:23 -0500
feat(defaults): per-platform 'guifont' default #37175
Problem:
Font rendering and kerning are subpar in GUIs.
Solution:
Set default 'guifont' based on common CSS fonts per:
https://github.com/system-fonts/modern-font-stacks#monospace-code
Diffstat:
6 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
@@ -3344,7 +3344,7 @@ A jump table for the options with a short description can be found at |Q_op|.
<
*'guifont'* *'gfn'* *E235* *E596*
-'guifont' 'gfn' string (default "")
+'guifont' 'gfn' string (default "Source Code Pro, DejaVu Sans Mono, Courier New")
global
This is a list of fonts which will be used for the GUI version of Vim.
In its simplest form the value is just one font name. When
diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua
@@ -3237,7 +3237,7 @@ vim.go.gcr = vim.go.guicursor
---
---
--- @type string
-vim.o.guifont = ""
+vim.o.guifont = "Source Code Pro, DejaVu Sans Mono, Courier New"
vim.o.gfn = vim.o.guifont
vim.go.guifont = vim.o.guifont
vim.go.gfn = vim.go.guifont
diff --git a/src/nvim/option_vars.h b/src/nvim/option_vars.h
@@ -32,6 +32,17 @@
"%*[^\"]\"%f\"%*\\D%l: %m,\"%f\"%*\\D%l: %m,%-Gg%\\?make[%*\\d]: *** [%f:%l:%m,%-Gg%\\?make: *** [%f:%l:%m,%-G%f:%l: (Each undeclared identifier is reported only once,%-G%f:%l: for each function it appears in.),%-GIn file included from %f:%l:%c:,%-GIn file included from %f:%l:%c\\,,%-GIn file included from %f:%l:%c,%-GIn file included from %f:%l,%-G%*[ ]from %f:%l:%c,%-G%*[ ]from %f:%l:,%-G%*[ ]from %f:%l\\,,%-G%*[ ]from %f:%l,%f:%l:%c:%m,%f(%l):%m,%f:%l:%m,\"%f\"\\, line %l%*\\D%c%*[^ ] %m,%D%*\\a[%*\\d]: Entering directory %*[`']%f',%X%*\\a[%*\\d]: Leaving directory %*[`']%f',%D%*\\a: Entering directory %*[`']%f',%X%*\\a: Leaving directory %*[`']%f',%DMaking %*\\a in %f,%f|%l| %m"
#endif
+// Default values for 'guifont'
+#ifdef MSWIN
+# define DFLT_GFN "Cascadia Code, Cascadia Mono, Consolas, Courier New"
+#elif defined(__APPLE__)
+# define DFLT_GFN "SF Mono, Menlo, Monaco, Courier New"
+#elif defined(__linux__)
+# define DFLT_GFN "Source Code Pro, DejaVu Sans Mono, Courier New"
+#else
+# define DFLT_GFN "DejaVu Sans Mono, Courier New"
+#endif
+
#define DFLT_GREPFORMAT "%f:%l:%m,%f:%l%m,%f %l%m"
// Possible values for 'encoding'
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
@@ -3996,7 +3996,9 @@ local options = {
},
{
abbreviation = 'gfn',
- defaults = '',
+ defaults = {
+ if_true = macros('DFLT_GFN', 'string'),
+ },
desc = [=[
This is a list of fonts which will be used for the GUI version of Vim.
In its simplest form the value is just one font name. When
diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua
@@ -210,6 +210,7 @@ describe(':TOhtml', function()
exec('set termguicolors')
local bg = fn.synIDattr(fn.hlID('Normal'), 'bg#', 'gui')
local fg = fn.synIDattr(fn.hlID('Normal'), 'fg#', 'gui')
+ exec_lua [[vim.o.guifont='Courier New' ]]
n.command('2,2TOhtml')
local out_file = api.nvim_buf_get_name(api.nvim_get_current_buf())
eq({
@@ -221,7 +222,7 @@ describe(':TOhtml', function()
'<title></title>',
('<meta name="colorscheme" content="%s"></meta>'):format(api.nvim_get_var('colors_name')),
'<style>',
- '* {font-family: monospace}',
+ ('* {font-family: "%s",monospace}'):format(n.eval('&guifont')),
('body {background-color: %s; color: %s}'):format(bg, fg),
'.Visual {background-color: #9b9ea4}',
'</style>',
diff --git a/test/functional/ui/options_spec.lua b/test/functional/ui/options_spec.lua
@@ -45,6 +45,7 @@ describe('UI receives option updates', function()
table.insert(clear_opts.args_rm or {}, '--cmd')
clear(clear_opts)
screen = Screen.new(20, 5, screen_opts)
+ defaults.guifont = eval('&guifont')
-- NB: UI test suite can be run in both "linegrid" and legacy grid mode.
-- In both cases check that the received value is the one requested.
defaults.ext_linegrid = screen._options.ext_linegrid or false