How can I change the font's style for VS Code's "Inlay Hints" feature?
I attempted to search for an answer, but could only find how to change the color, not the style.
I would like the word target
in the image below to render italic .
I tried the following, however, it did not work...
{
scope: "inlayHint",
settings: {
fontStyle: "italic",
},
},
I also tried adding editor.inlayHint
to the scope, but the attempt was without success.
italic
isn't Possible. As I stated above, setting the font-style to italic is not possible. There is, however, a workaround, and it works pretty darn well. Before I explain the workaround, I think its important to note that the first solution I tried to use, was to set the font to an italic variant, unfortunately setting "editor.inlayHints.fontFamily"
to an italic variant of a font was something that VS Code didn't seem to allow. I have seen this in many other situations. The idea is, since you can't do this "fontStyle": "italic"
, you just change the font to an italic version.
// @file "settings.json"
{
"editor.inlayHints.fontFamily": "'Cascadia Code Italic'"
}
...however, it unfortunately doesn't work that way — or at-least not in this situation . Not only do italic varients not work, but neither do bold variants and/or expanded variants (ie 'Inconsolata SemiExpanded', 'Inconsolata Bold', etc...) .
There is no "editor.inlayHints.fontStyle"
setting.
Well we can set the font-family using "editor.inlayHints.fontFamily"
.
Its a bit suprising that we can set the font, but not the font's style. I am not sure why they designed it this way, but it's obvious that they built the feature with specific constraints for reasons that are beyond me (reading the feature's development feed on GitHub would probably help anyone who wanted to know more about why the feature works how it does). Nevertheless, we have a highly customizable setting, that actually gives us far more control than the setting that we established, does not exist , editor.inlayHints.font
.
What I do, personally, which has a cool tricked-out look, is I find a non-monospaced hand-written style of font — usually from Google Fonts — and I assign that to the font-family. It took me a while to find some fonts that work. Anyone who has ever played with fonts, trying to find which font works best for them to write code with, will know: Picking fonts that are used anywhere inside the editor (or inside your code) is going to require great scrutiny, and the longer you code, the more set in your ways you get, so this can actually be a time consuming setting to configure. It took me an hour to settle on a font, and I settled on using the "Sriracha" font-family. Siracha is oblique in appearance (looks italic), its readable in the editor, it renders well in the editor (which not all fonts are going to do), and its slightly bolder than the standard weight of the font I use wich is Cascadia Code.
When changing the font family, there are a couple other settings that help to configure this feature.
Download the italic &/or bold style font you wont from Google Fonts , Font Squirrel , or some other font source you perfer.
Set the font family using "editor.inlayHints.fontFamily" .
Critique the fonts configuration using the other settings available below.
// @file "settings.json"
{
// Font Family
"editor.inlayHints.fontFamily": "/*NAME OF FONT FAMILY*/",
// Font Size
"editor.inlayHints.fontSize": 14, // <-- Set the font-size you want
// Theme Colors Override
"workbench.colorCustomizations": {
// Overrides Theme Default Colors for InlayHints feature
"editorInlayHint.background": "#00001CCC",
"editorInlayHint.foreground": "#99FFBBCC",
// Overrides Theme Parameter hints fg for InlayHints feature
"editorInlayHint.parameterBackground": "#00001CCC",
"editorInlayHint.parameterForeground": "#99FFBBCC",
// Overrides Theme Type hints fg for InlayHints feature
"editorInlayHint.typeBackground": "#08000088",
"editorInlayHint.typeForeground": "#DDEEFF88"
},
}
By being able to set the inlayHints font family to anything we want, we can achieve any sort of font style we want.
In settings.json
you need a line like
"editor.inlayHints.fontFamily": "'Myfontitalic'",
Now, it seems vscode has some trouble reading a font name with non alphanumeric characters, if for instance the italic version is "Myfont-Italic" or "Myfont Italic".
A solution is to copy and rename the font to a new name, like "Myfontitalic", without spaces or other characters.
What I did was for Ubuntu but the same idea should work on any Linux, and probably Windows, using other tools (fontforge?)
apt install fonttools font-manager
to get ttx
a utility to change font info (font-manager is also useful) /usr/share/fonts/...
or ~/.local/share/fonts
)cp ~/.local/share/fonts/Myfont-Italic.otf ~/temp.otf
and cd
to go homettx temp.otf
as temp.ttx
temp.ttx
( vi , ...), and change all "Myfont-Italic", "Myfont Italic"... (relevant names) to a unique "Myfontitalic" name, save.ttx temp.ttx
(creates Myfontitalic.otf
if it was an otf file) To install the new font (locally), either double-click on it in the file explorer ( ~/Myfontitalic.otf
) or use a tool. Restart font-manager
, the new font should be visible.
Restart vscode and add the line above in settings.json
.
on a Mac find the font variant name like this:
PostScript Name
name in VS Code - for example "editor.inlayHints.fontFamily": "DankMono-Italic"
No one tells you where to edit this and that makes it a pain in the butt.
File>Preferences>Settings, search for color customizations, click "Edit in settings.json"
{
"workbench.colorCustomizations": {
"editorInlayHint.background": "#00000000",
"editorInlayHint.foreground": "#666666FF",
},
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.