4 ms·
How would you configure a text editor or terminal to use different fonts based on syntax (e.g. neon for code, argon for comments)?
by helix278 3y ago
How would you configure a text editor or terminal to use different fonts based on syntax (e.g. neon for code, argon for comments)?
- leipert 3y agoIn vscode probably easy because it is all CSS? Other editors/terminal emulators would probably need to add support for this.
- idan 3y agoHi! I worked on this at Next. Unfortunately, it's on the editor to support mixing fonts. There's never been multiple compatible monospaced fonts before so no editors really support this yet. Lots of editors also don't support variable typefaces properly yet (ahem, VS Code) but this is going to change. Ultimately what you're describing is the future! But we have to release the typefaces to bootstrap that future. We made a prototype extension that hack it into VS Code. But they're hacky af and not really releasable.
- ctenb 3y agoI wonder if terminal escape code sequences would arise to support this too!
- afc 3y agoDo you know of any Linux terminal (eg. xterm, gnome-terminal, etc.) that would support multiple fonts? I'm intrigued, shouldn't be very hard to add support to command-line programs (once terminals supported it).
- naikrovek 3y agoWezterm does. expansive configuration and scripting abilities are available.
- aidenn0 3y ago> so no editors really support this yet Emacs and Vim have both supported this since at least last century.
- tmtvl 3y agoTo expand on this, Emacs uses a system called "faces" to draw different textual elements, for example font-lock-comment-face to draw comments. Faces can have different attributes, like font family, foreground colour, background colour, having a box around it,... So if I want to use a variable pitch font (like say... DejaVu Sans) to draw comments, I can set the font-lock-comment-face to use the "DejaVu Sans" family.
- layer8 3y agoSome IDEs support configuring the font per syntactic category, i.e. with the same granularity as syntax highlighting colors.
- HellsMaddy 3y agoI've configured Neovim's syntax highlighting to make comments bold italic, and then I've configured my terminal (Kitty) to display a different font for bold italic text. Using this approach, you can use up to 4 different fonts: One for normal text, one for italic, one for bold, and one for bold italic. And the font for each group doesn't necessarily need to be that style, e.g. you can use a non-bold version for the `bold` font, etc.
- bool3max 3y agoFeels very hacky.
- HellsMaddy 3y agoThe terminal is by nature very hacky.
- overbytecode 3y agoI use kitty and neovim too, would you mind sharing how you got this to work?
- HellsMaddy 3y agoIn Neovim, make sure your desired highlight groups have `gui=bold,italic`, e.g. hi Comment guifg=#7e7490 gui=bold,italic In Kitty, set the desired fonts: font_family IosevkaTerm Nerd Font Mono italic_font IosevkaTerm Nerd Font Mono bold_font IosevkaTerm Nerd Font Mono bold_italic_font Iosevka Term Slab