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

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。