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".
# Build libwcwidth-icons.so and copy it to /usr/lib/ by default.
sudo make install
sudo layman -a powerman
sudo emerge wcwidth-icons
# Fix icon width for Nerd Fonts v3 (non-Mono variant).
export LD_PRELOAD=/usr/lib/libwcwidth-icons.so
Then run urxvt/xterm/zsh/… using font with double-width icons.
# Fix icon width for Nerd Fonts v3 (non-Mono variant).
export LESSUTFCHARDEF="23fb-23fe:w,2665:w,2b58:w,e000-e09f:w,e0a0-e0bf:p,e0c0-f8ff:w,f0001-fffff:w"
Add this to your Vim configuration:
" Fix icon width for Nerd Fonts v3 (non-Mono variant).
call setcellwidths([
\ [ 0x23fb, 0x23fe, 2 ],
\ [ 0x2665, 0x2665, 2 ],
\ [ 0x2b58, 0x2b58, 2 ],
\ [ 0xe000, 0xe09f, 2 ],
\ [ 0xe0c0, 0xf8ff, 2 ],
\ [ 0xf0001, 0xfffff, 2 ],
\ ])
Add this to your Neovim configuration:
-- Fix icon width for Nerd Fonts v3 (non-Mono variant).
vim.fn.setcellwidths({
{ 0x23fb, 0x23fe, 2 },
{ 0x2665, 0x2665, 2 },
{ 0x2b58, 0x2b58, 2 },
{ 0xe000, 0xe09f, 2 },
{ 0xe0c0, 0xf8ff, 2 },
{ 0xf0001, 0xfffff, 2 },
})