欢迎光临散文网 会员登陆 & 注册

Vim Powerline & Fonts(Fira Code)

2022-05-25 16:14 作者:紧果呗  | 我要投稿

# ===🗝 Airline or Powerline - Tab Bar/Status Bar

  • - https://github.com/powerline/powerline

  • - https://github.com/Lokaltog/powerline

  • - https://github.com/vim-airline/vim-airline

  • - https://github.com/vim-airline/vim-airline-thremes

  • - https://linuxconfig.org/introduction-to-powerline-the-statusline-plugin-for-vim

  • - https://www.alexwhittemore.com/gvim-with-powerline-on-windows-8-64bit/

  • - https://www.ricalo.com/blog/install-powerline-windows/

Windows Terminal Settings

Vim 状态条插件的内容有三个部分:

  •    - 字体文件的介绍,以及安装与使用;

  •    - Vim-Airline 和 Vim-Powerline 的差别;

  •    - Vim-Airline 和 Vim-Powerline 安装与配置;

全文参考 https://github.com/jimboyeah/run-snippet/blob/master/material/vim_flavor.md

使用 Windows Terminal 终端应用,Set the shell's title

  • - https://docs.microsoft.com/en-us/windows/terminal/tutorials/tab-title

 PowerShell  >>>>  $Host.UI.RawUI.WindowTitle = "New Title" 

   Command  >>>>  Prompt  TITLE "New Title"               

           bash* >>>>  echo -ne "\033]0;New Title\a"           


Vim-Airline 和 Vim-Powerline 都是非常棒棒的状态条、标签块插件,可优化 Vim 原有的 Tab 有点混乱的状。


作为更早期的插件,Powerline 使用 Python 脚本开发,不仅支持 Vim,看起来块头更大。并且在 Vim 配置上也更显异类,并且混乱,需要有一定的 Python 配置能力和 Vim 脚本接口扩展知识。


另外,因为 Powerline 使用更好看箭头,需要安装额外的 Arimo for Powerline 字体。只在 Windows WSL 系统上安装,Windows Terminal 上并没有效果,并且很卡顿体验不够好:


    sudo apt install --yes powerline
    sudo apt-get install fonts-powerline

在 Windows 上的 NeoVim 中也出现了错误:

    AttributeError: 'LegacyVim' object has no attribute 'bindeval'

安装字体注意,因为在 Windows WSL 环境下使用 Vim,控制台是在宿主系统上执行的,字体就要安装在宿主系统上。因为 Windows Terminal 运行在宿主系统上,WSL 是子系统,字体应该在宿主机上安装。


字体特点介绍如,按紧凑度升序:

Cascadia Code、Fira Code、JetBrains Mono 三款字体均支持连字,>= <= => -> != <> 这类两字并作一格,也均有非连字版本,字体均强调了 'l' 的辨识度。

  • - [Arimo for Powerline](https://github.com/powerline/fonts)

  • - [Cascadia Code](https://github.com/microsoft/cascadia-code/releases)

  • - [Fira Code](https://github.com/tonsky/FiraCode/releases)

  • - [JetBrains Mono](https://github.com/JetBrains/JetBrainsMono/releases)

  • - [Sarasa Gothic 更纱黑体](https://github.com/be5invis/Sarasa-Gothic)


各字体的变体:

Fira Code 是 Mozilla 公司主推的字体系列,专为写程序设计的字体。出来具有等宽等基本属性外,还加入了编程连字特性(ligatures),这点做得非常好,并且对视网膜高清屏有支持,有 Retina 变体。


Fira Code 就是利用这个特性对编程中的常用符号进行优化,比如把输入的「!=」直接显示成 「≠」 或者把 「>=」 变成 「≥ 」 等等,以此来提高代码的可读性。并且 1liIoOpP0 这此字符辨识度极高。

Fira Code 对 Unicode 字符集支持度还非常高,其中 Medium 变体中文有粗线不一问题;

Fira Code 字体效果

更纱黑体是一种中文编程字体,包含以下样式:


   - Sarasa Gothic / 更纱黑体:基于Inter,全宽引号

   - Sarasa UI / 更纱黑体 UI:基于Inter,窄引号


以下 PowerSHell 脚本供参考,可以直接下载 Powerline 字包,解压后执行安装脚本,它会执行 Windows 字体安装程序,将字体安装到 Windows Fonts 目录下:

$url = "https://github.com/powerline/fonts/archive/master.zip"

powershell -command "& { iwr $url -OutFile ~\fonts.zip }"

Expand-Archive -Path ~\fonts.zip -DestinationPath ~

~\fonts-master\install.ps1

另一个替代选择是微软的 Cascadia Code 字体,它支持 Powerline Glyph。Windows Terminal 要使用此字体,需要修改属性,或者直接修改配置文件 settings.json,通过 Ctrl-Shift-P 打开 Open Settings file,或设置 Open settings ⇨ PowerShell ⇨ apperance ⇨ Text ⇨ Font Face 指定:

"fontFace" : "Cascadia Mono PL",

Cascadia Code 字体包内含有 OTF\TTF\WOFF2 三种格式,通常选择其中 TTF 格式安装。WOFF2 这种格式在网页上应用很常见,因为它体积更小。选择其中一个字体文件,双击打开字体浏览程序安装,或者多选通过右键菜单批量安装。


另外,字体包中还提供了 static 目录下的字体文件,这部分是静态字体,在 Variable 字体不支持的情况可以使用,一般都是使用可变形字体。变体字的好处就是包含了 Thin/Light/Medium/Bold 等变体字形,使用起来比较方便。Cascadia Code 目前有四个组合变体,主要是 Code 和 Mono 两种,后者是等宽不连字,PL 表示 PowerLine。


Cascadia Code 是 Microsoft 提供的一种新的等宽字体,可为命令行应用程序和文本编辑器提供全新的体验。 Cascadia Code 是与 Windows 终端一起开发的。 建议将此字体与终端应用程序和文本编辑器(如 Visual Studio 和 Visual Studio Code)一起使用。


Cascadia Code is a purpose-built monospaced TrueType font for Windows Terminal, the new command-line interface for Microsoft Windows. It includes programming ligatures and was designed to enhance the look and feel of Windows Terminal, terminal applications and text editors such as Visual Studio and Visual Studio Code. The font is open source under the SIL Open Font License and available on GitHub. 


Windows 终端在其包中提供 Cascadia Code 和 Cascadia Mono,字体信息如下:

Font Variants

  •    1. Cascadia Code: standard version of Cascadia

  •    2. Cascadia Mono: a version of Cascadia that doesn't have ligatures

  •    3. Cascadia (Code|Mono) PL: a version of Cascadia that has embedded Powerline symbols



目前,Vim-Powerline 已经停止更新,并转向 Powerline 项目。


在 Vim 配置脚本中测试当前环境是否对 Python 3.x 的支持。


配置上需要 Python 基础,需要使用 `pip` 和 `setuptools` 包安装工具,并且对 Windows 系统支持还不好,PowerShell 脚本也没提供。

Airline 更轻量化,安装后免配置即可用,还可以搭配主题,Vundle 或 Vim-Plug 方式安装如下。可以在 Airline 中使用 Powerline 的好看字体,通过 g:airline_powerline_font 全局变量启用。

图形界面字体还可以通过 guifont 选项设置,格式参考 :help guifont。


以 Vim-Plug 为例,修改 .vimrc 配置文件后,通过 :PlugStatus 查询插件状态,通过 :PlugInstall 安装插件。


插件样式主题命令参考:


   ⭆ In .vimrc, use let g:airline_theme='<theme>', e.g. ='simple'

   ⭆ :AirlineTheme <theme> to set the theme, e.g. :AirlineTheme simple

   ⭆ :AirlineTheme random to set a randomly selected

   ⭆ `:help airline` `:help airline-themes` to get help


Vim Powerline & Fonts(Fira Code)的评论 (共 条)

分享到微博请遵守国家法律