qvacua / vimr

VimR — Neovim GUI for macOS in Swift
https://twitter.com/VimRefined
MIT License
6.62k stars 218 forks source link

Invalid font(s): gufont=monospace:h17; very slow startup #944

Open elmehalawi opened 2 years ago

elmehalawi commented 2 years ago

Vimr takes several second to start and when it does, it gives me the error:

E596: Invalid font(s): gufont=monospace:h17

I'm not sure why it's trying to use the font "monospace:h17", I never set that. In the settings, I set the font to Fira Code with a height of 13.

What I tried

I tried setting the font correctly in my lua config:

vim.opt.guifont = "Fira Code Regular Nerd Font Complete:h13"

This doesn't seem to have any effect on its own.

I also tried using an application called FontForge to generate a new font (just copied another) with the name "monospace", so that Vimr picks that up on startup. This actually kind of worked, Vimr started immediately, and it doesn't show an error, but for some reason it set the font size to 17.

If I try both of those things (create a font called "monospace", and also set the guifont to the proper font), it does an infinite loop between monospace:h17 and firacode:h13, and the only way I could find to get out of it was to force quit Vimr.

Any help would be appreciated.

HungryJoe commented 2 years ago

I was seeing the same error when transitioning to VimR from MacVim. I had explicitly set guifont in my vimrc like:

set guifont=Monofur\ Nerd\ Font\ Mono

which is the name of the font according to FontBook and worked just fine for MacVim. However, like in your case, when launching VimR for the first time I was greeted with this error:

E596: Invalid font(s): gufont=Monofur Nerd Font Mono

after a few seconds of loading time, which was confusing in no small part because the relevant option is called guifont, not gufont.

After some searching, I found a claim made in this neovim-dot-app issue comment that

Neovim doesn't support guifont

This smelled funny since it didn't cite any sources, so I hunted for some official docs. It turns out that the guifont option is present in the official help files, negating the above claim. But it mentions something bizarre:

The font name depends on the GUI used.

Sure enough, VimR was expecting a different name than what FontBook showed for this font: After using its built-in font picker to set the font to Monofur Nerd Font Mono, it gave me

set guifont=monofur_Nerd_Font_Complete_Mono:h36

when I tried tab-completing

set guifont=

So I just copy-pasted that line into my .vimrc and it worked like a charm!

tl;dr

The guifont option is super weird in Neovim because each UI might expect a different name for the same font. So just use VimR's font picker (under Appearance in preferences) instead 🙂