mkdir700

mkdir700

如何在Neovim和WezTerm中实现代码关键词的斜体显示

前言#

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

image

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

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/

本文将使用 Neovim + 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',
	  },
	},
}

配置 Neovim#

在 Neovim 中需要使用支持斜体展示的主题,我使用的是 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 = {},                 
  },                                
}

效果#

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

image

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。