Skip to content

Instantly share code, notes, and snippets.

@sagax
Created January 24, 2026 20:55
Show Gist options
  • Select an option

  • Save sagax/900768aa10da06039079d2d875017813 to your computer and use it in GitHub Desktop.

Select an option

Save sagax/900768aa10da06039079d2d875017813 to your computer and use it in GitHub Desktop.
vim: set fontname & fontsize
vim9script
def IsSymSpace(ord: number): bool
if ord == 32
return true
endif
return false
enddef
def IsSymEqual(ord: number): bool
if ord == 61
return true
endif
return false
enddef
def IsSymDigit(ord: number): bool
if ord >= 48 && ord <= 57
return true
endif
return false
enddef
def IsSymChar(ord: number): bool
if (ord >= 65 && ord <= 90) || (ord >= 97 && ord <= 122)
return true
endif
return false
enddef
def IsSpecChar(ord: number): bool
var allowed_symbols = [
45, # дефис
46, # точка
44, # запятая
40, # (
41, # )
39, # '
43, # +
42, # *
35, # #
36, # $
37, # %
38, # &
64, # @
33, # !
63, # ?
95, # _
59, # ;
58, # :
91, # [
93, # ]
123, # {
125, # }
92, # \
47, # /
124, # |
60, # <
62, # >
126, # ~
94, # ^
96 # `
]
return index(allowed_symbols, ord) >= 0
enddef
g:font_was_changed = true
g:font_params = {name: null, size: null}
def ParseFontParams(fparams: string, from_execute: bool = false): dict<any>
if g:font_was_changed == false
return g:font_params
endif
var result: dict<any> = {
name: null,
size: null,
}
var name_chars: list<string> = []
var size_chars: list<string> = []
var state = 0 # 0 ждём `=`, 1 сбор символов имени, 2 сбор символов размера
if from_execute
state = 0
else
state = 1
endif
for i in range(len(fparams))
var ch = fparams[i]
var ord = char2nr(ch)
if state == 0 # ждём символ '='
if IsSymEqual(ord)
state = 1
endif
continue
endif
var ch_next: string
var ord_next: number
var i_next: number = i + 1
if i_next < len(fparams)
ch_next = fparams[i_next]
ord_next = char2nr(ch_next)
endif
if state == 1
if IsSymSpace(ord) && IsSymDigit(ord_next) # т.е. если сейчас пробел, а следующий символ это цифра, то ждём размер шрифта
state = 2
continue
endif
if IsSymChar(ord) || IsSymSpace(ord)
name_chars->add(ch)
endif
endif
if state == 2
if IsSymDigit(ord)
size_chars->add(ch)
endif
endif
endfor
result.name = name_chars->join('')
result.size = str2nr(size_chars->join(''))
g:font_params = result
g:font_was_changed = false
return result
enddef
def GetFontParams(): dict<any>
var is_gui = has("gui_running") ? true : false
if is_gui == false
return g:font_params
endif
if g:font_was_changed == true
#ParseFontParams(execute('set guifont?'), true)
ParseFontParams(&guifont)
g:font_was_changed = false
endif
return g:font_params
enddef
def CSetFontParams(name: string, size: number)
var font_params_string = name .. " " .. size
&guifont = font_params_string
g:font_was_changed = true
enddef
def g:CGetFontParams()
var font_params: dict<any>
font_params = GetFontParams()
echom string(font_params)
enddef
g:font_name_index = 0
var font_names: list<string> = [
'Anonymice Powerline Plus Nerd File Types Mono Plus Font Awesome Bold',
'Droid Sans Mono for Powerline Plus Nerd File Types Bold',
'Monofur Nerd Font Mono',
'Monoid Nerd Font Mono Bold',
'Iosevka Bold',
'Iosevka Thin Oblique',
'Iosevka Light',
'JetBrains Mono Bold',
'JetBrains Mono ExtraBold',
'Meslo LG L DZ Regular for Powerline',
'Meslo LG S DZ for Powerline',
'RobotoMono Nerd Font Mono',
'SpaceMono Nerd Font Mono',
'Overpass Nerd Font Mono',
'OverpassMono Nerd Font',
'UbuntuMono Nerd Font Mono',
'Lekton Nerd Font Mono',
'Sauce Code Powerline Plus Nerd File Types Mono',
'Sauce Code Pro Plus Nerd File Types Mono Plus Font Awesome',
'Sauce Code Pro Plus Nerd File Types Mono Bold',
'SauceCodePro Nerd Font Mono Bold',
'DejaVu Sans Mono for Powerline Plus Nerd File Types Bold',
'DejaVuSansMono Nerd Font Bold',
'FantasqueSansMono Nerd Font Mono Bold',
'FantasqueSansMono Nerd Font Bold',
'FantasqueSansMono Nerd Font Bold',
'JetBrainsMono NF',
'IBM Plex Mono Bold',
'Fira Code',
'JetBrainsMono Nerd Font Mono Bold',
]
g:font_names = font_names
def g:CSetFontNameNext()
var is_gui = has("gui_running") ? true : false
if is_gui == false
return
endif
var font_params: dict<any>
font_params = GetFontParams()
var font_name: string = font_names[g:font_name_index]
g:font_name_index = g:font_name_index + 1
if g:font_name_index == len(g:font_names)
g:font_name_index = 0
endif
CSetFontParams(font_name, font_params.size)
enddef
def g:CSetFontNamePrev()
var is_gui = has("gui_running") ? true : false
if is_gui == false
return
endif
var font_params: dict<any>
font_params = GetFontParams()
var font_name: string = font_names[g:font_name_index]
g:font_name_index = g:font_name_index - 1
if g:font_name_index < 0
g:font_name_index = len(g:font_names) - 1
endif
CSetFontParams(font_name, font_params.size)
enddef
# Изменение размера шрифта
def g:CSetFontSize(font_size_new: any)
var is_gui = has("gui_running") ? true : false
if is_gui == false
return
endif
var font_params: dict<any>
font_params = GetFontParams()
CSetFontParams(font_params.name, font_size_new)
enddef
def g:CSetFontSizePlus()
var is_gui = has("gui_running") ? true : false
if is_gui == false
return
endif
var font_params: dict<any>
font_params = GetFontParams()
var font_size_new = font_params.size + 1
call g:CSetFontSize(font_size_new)
enddef
def g:CSetFontSizeMinus()
var is_gui = has("gui_running") ? true : false
if is_gui == false
return
endif
var font_params: dict<any>
font_params = GetFontParams()
var font_size_new = font_params.size - 1
call g:CSetFontSize(font_size_new)
enddef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment