Mkdir700's Note

Mkdir700's Note

nvim + wezterm 关键词斜体展示

71
2024-02-01
nvim + wezterm 关键词斜体展示

前言

不知道你有没有见过,在一些人的 VIM 中的代码,一部分是正体一部分是斜体,就像这样:

我还是比较喜欢这样子的风格:

When it comes to programming fonts, I prefer something thin and relatively condensed, but with a more informal, flowing and human style for standouts like comments and certain keywords.

在选择编程字体时,我更喜欢一些较细、相对紧凑的字体,但对于注释和特定关键词等突出部分,我更偏向于一种更不正式、流畅和人性化的风格。

—— 来自 https://rubjo.github.io/victor-mono/

那么本文将使用 nvim+ Wezterm 实现上方的展示风格。

安装字体

点击进入 victor-mono 官网

点击下载 victor-mono

1) 下载字体

2) 解压 ZIP 文件

3) 安装字体文件

Windows 选择安装 ttf 格式的,我只用 victor-mono 的斜体,所以我只安装了 VictorMono-Italic.ttfVictorMono-BoldItalic.ttf

配置 Wezterm

在当前用户目录下找到 .wezterm.lua ,如果没有则新建。

配置 config.fontconfig.font_rule ,我这里采用的策论是,默认使用 Cascadia Mono,如果是斜体则使用 Victor Mono

config.font = wezterm.font_with_fallback {
	'Cascadia Mono',
	'DengXian'
}
config.font_rules = {
	{
	  intensity = 'Bold',
	  italic = true,
	  font = wezterm.font {
		family = 'Victor Mono',
		weight = 'Bold',
		style = 'Italic',
	  },
	},
	{
	  italic = true,
	  intensity = 'Half',
	  font = wezterm.font {
		family = 'Victor Mono',
		weight = 'DemiBold',
		style = 'Italic',
	  },
	},
	{
	  italic = true,
	  intensity = 'Normal',
	  font = wezterm.font {
		family = 'Victor Mono',
		style = 'Italic',
		weight = 'Bold',
	  },
	},
}

配置 NVIM

在 Nvim 中需要使用支持斜体展示的主体,比如:catppuccin

我使用的就是 catppuccin,它可以搭配 lsp 和 tressitter 使用,这样可以让代码中的特定部分展示不同的风格,比如代码关键字采用斜体展示。

require("catppuccin").setup({       
  styles = {                        
    comments = { "bold" },          
    properties = { "bold" },        
    functions = { "bold" },         
    keywords = { "italic" },        
    operators = { "bold" },         
    conditionals = { "italic" },    
    loops = { "italic" },           
    booleans = { "bold", "italic" },
    numbers = {},                   
    types = {},                     
    strings = {},                   
    variables = {},                 
  },                                
}

效果

如下图所示,仅关键字部分斜体展示,其余部分还是正常的。