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
This commit is contained in:
Rahul Yedida
2026-02-16 09:05:23 -05:00
committed by GitHub
parent e6fae64454
commit 249f305bbc
6 changed files with 19 additions and 4 deletions

View File

@@ -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'* *E235* *E596*
'guifont' 'gfn' string (default "") 'guifont' 'gfn' string (default "Source Code Pro, DejaVu Sans Mono, Courier New")
global global
This is a list of fonts which will be used for the GUI version of Vim. 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 In its simplest form the value is just one font name. When

View File

@@ -3237,7 +3237,7 @@ vim.go.gcr = vim.go.guicursor
--- ---
--- ---
--- @type string --- @type string
vim.o.guifont = "" vim.o.guifont = "Source Code Pro, DejaVu Sans Mono, Courier New"
vim.o.gfn = vim.o.guifont vim.o.gfn = vim.o.guifont
vim.go.guifont = vim.o.guifont vim.go.guifont = vim.o.guifont
vim.go.gfn = vim.go.guifont vim.go.gfn = vim.go.guifont

View File

@@ -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" "%*[^\"]\"%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 #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" #define DFLT_GREPFORMAT "%f:%l:%m,%f:%l%m,%f %l%m"
// Possible values for 'encoding' // Possible values for 'encoding'

View File

@@ -3996,7 +3996,9 @@ local options = {
}, },
{ {
abbreviation = 'gfn', abbreviation = 'gfn',
defaults = '', defaults = {
if_true = macros('DFLT_GFN', 'string'),
},
desc = [=[ desc = [=[
This is a list of fonts which will be used for the GUI version of Vim. 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 In its simplest form the value is just one font name. When

View File

@@ -210,6 +210,7 @@ describe(':TOhtml', function()
exec('set termguicolors') exec('set termguicolors')
local bg = fn.synIDattr(fn.hlID('Normal'), 'bg#', 'gui') local bg = fn.synIDattr(fn.hlID('Normal'), 'bg#', 'gui')
local fg = fn.synIDattr(fn.hlID('Normal'), 'fg#', 'gui') local fg = fn.synIDattr(fn.hlID('Normal'), 'fg#', 'gui')
exec_lua [[vim.o.guifont='Courier New' ]]
n.command('2,2TOhtml') n.command('2,2TOhtml')
local out_file = api.nvim_buf_get_name(api.nvim_get_current_buf()) local out_file = api.nvim_buf_get_name(api.nvim_get_current_buf())
eq({ eq({
@@ -221,7 +222,7 @@ describe(':TOhtml', function()
'<title></title>', '<title></title>',
('<meta name="colorscheme" content="%s"></meta>'):format(api.nvim_get_var('colors_name')), ('<meta name="colorscheme" content="%s"></meta>'):format(api.nvim_get_var('colors_name')),
'<style>', '<style>',
'* {font-family: monospace}', ('* {font-family: "%s",monospace}'):format(n.eval('&guifont')),
('body {background-color: %s; color: %s}'):format(bg, fg), ('body {background-color: %s; color: %s}'):format(bg, fg),
'.Visual {background-color: #9b9ea4}', '.Visual {background-color: #9b9ea4}',
'</style>', '</style>',

View File

@@ -45,6 +45,7 @@ describe('UI receives option updates', function()
table.insert(clear_opts.args_rm or {}, '--cmd') table.insert(clear_opts.args_rm or {}, '--cmd')
clear(clear_opts) clear(clear_opts)
screen = Screen.new(20, 5, screen_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. -- 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. -- In both cases check that the received value is the one requested.
defaults.ext_linegrid = screen._options.ext_linegrid or false defaults.ext_linegrid = screen._options.ext_linegrid or false