Skip to content

Support fonts with double-width icons in xterm/rxvt-unicode/zsh/vim/…

License

Notifications You must be signed in to change notification settings

powerman/wcwidth-icons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wcwidth-icons

Support fonts with double-width icons in xterm/rxvt-unicode/zsh/vim/…

If fonts with icons like Nerd Fonts are used with some terminals like rxvt-unicode then icons must have single-width (Nerd Fonts calls this "Mono" font, generated by Nerd Fonts Font Patcher with option --use-single-width-glyphs) to work correctly. This makes icons too small (about ¼ of normal size for most icons).

To fix this for most applications (like xterm/rxvt-unicode/zsh/…) which use libc function (like wcwidth(3) or wcswidth(3)) to get symbol width you can use provided library in LD_PRELOAD environment variable.

Some other applications may need extra configuration or a patch (see below).

With these fixes you should use Nerd Fonts with "Propo" font name suffix instead of "Mono".

Install

# Build libwcwidth-icons.so and copy it to /usr/lib/ by default.
sudo make install

Gentoo Linux

sudo layman -a powerman
sudo emerge wcwidth-icons

# Patch Vim
sudo mkdir -p /etc/portage/patches/app-editors/vim{,-core}/
sudo wget https://github.com/powerman/wcwidth-icons/raw/master/patches/vim/wcwidth-icons.patch \
    -O /etc/portage/patches/app-editors/vim/wcwidth-icons.patch
sudo cp /etc/portage/patches/app-editors/vim{,-core}/wcwidth-icons.patch
sudo emerge -1 vim vim-core

Usage

export LD_PRELOAD=/usr/lib/libwcwidth-icons.so

Then run urxvt/xterm/zsh/… using font with double-width icons.

Other applications

Less

export LESSUTFCHARDEF="23fb-23fe:w,2665:w,2b58:w,e000-e00a:w,e0a0-e0a3:p,e0b0-e0bf:p,e0c0-e0c8:w,e0ca:w,e0cc-e0d7:w,e200-e2a9:w,e300-e3e3:w,e5fa-e6b5:w,e700-e7c5:w,ea60-ec1e:w,ed00-efce:w,f000-f2ff:w,f300-f375:w,f400-f533:w,f0001-f1af0:w"

Vim

Add this to your Vim configuration:

" Fix icon width for Nerd Fonts v3.2.1.
call setcellwidths([
\   [ 0x23fb, 0x23fe, 2 ],
\   [ 0x2665, 0x2665, 2 ],
\   [ 0x2b58, 0x2b58, 2 ],
\   [ 0xe000, 0xe00a, 2 ],
\   [ 0xe0c0, 0xe0c8, 2 ],
\   [ 0xe0ca, 0xe0ca, 2 ],
\   [ 0xe0cc, 0xe0d7, 2 ],
\   [ 0xe200, 0xe2a9, 2 ],
\   [ 0xe300, 0xe3e3, 2 ],
\   [ 0xe5fa, 0xe6b5, 2 ],
\   [ 0xe700, 0xe7c5, 2 ],
\   [ 0xea60, 0xec1e, 2 ],
\   [ 0xed00, 0xefce, 2 ],
\   [ 0xf000, 0xf2ff, 2 ],
\   [ 0xf300, 0xf375, 2 ],
\   [ 0xf400, 0xf533, 2 ],
\   [ 0xf0001, 0xf1af0, 2 ],
\ ])

Neovim

Add this to your Neovim configuration:

-- Fix icon width for Nerd Fonts v3.2.1.
vim.fn.setcellwidths({
    { 0x23fb, 0x23fe, 2 }, -- IEC Power Symbols
    { 0x2665, 0x2665, 2 }, -- Octicons
    { 0x2b58, 0x2b58, 2 }, -- IEC Power Symbols
    { 0xe000, 0xe00a, 2 }, -- Pomicons
    { 0xe0c0, 0xe0c8, 2 }, -- Powerline Extra
    { 0xe0ca, 0xe0ca, 2 }, -- Powerline Extra
    { 0xe0cc, 0xe0d7, 2 }, -- Powerline Extra
    { 0xe200, 0xe2a9, 2 }, -- Font Awesome Extension
    { 0xe300, 0xe3e3, 2 }, -- Weather Icons
    { 0xe5fa, 0xe6b5, 2 }, -- Seti-UI + Custom
    { 0xe700, 0xe7c5, 2 }, -- Devicons
    { 0xea60, 0xec1e, 2 }, -- Codicons
    { 0xed00, 0xefce, 2 }, -- Font Awesome
    { 0xf000, 0xf2ff, 2 }, -- Font Awesome
    { 0xf300, 0xf375, 2 }, -- Font Logos
    { 0xf400, 0xf533, 2 }, -- Octicons
    { 0xf0001, 0xf1af0, 2 }, -- Material Design
})

About

Support fonts with double-width icons in xterm/rxvt-unicode/zsh/vim/…

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published