You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何独立于语言与扩展自定义VS Code的Inlay Hint?

独立于语言与扩展自定义VS Code的Inlay Hint

需求

  • 自定义Inlay Hint的显示时机
  • 自定义其视觉样式
  • 通过workspace或user settings调整这些设置

动机

目前尚未找到简洁明了的一站式文档解答该问题,因此提出此问题并给出解答。

术语说明

内置并不等同于独立于语言。VS Code提供部分针对特定语言的内置设置,这类语言相关设置不在本次讨论范围内。

环境

VS Code 1.81版本


解决方案

1. 自定义显示时机

VS Code提供全局设置统一控制所有语言/扩展的Inlay Hint显示逻辑,支持多种触发模式:

  • 全局开关:通过editor.inlayHints.enabled设置,可选值包括:
    • on:始终显示
    • off:始终隐藏
    • offUnlessPressed:按住指定按键时显示
    • offUnlessHover:鼠标悬停时显示
  • 按键触发配置(对应offUnlessPressed模式):使用editor.inlayHints.toggleKey指定触发按键,示例配置:
    "editor.inlayHints.enabled": "offUnlessPressed",
    "editor.inlayHints.toggleKey": "Alt"
    

2. 自定义视觉样式

通过workbench.colorCustomizations和专属字体配置项调整Inlay Hint的外观:

  • 颜色配置:修改背景、前景、边框及不同类型提示的颜色,示例:
    "workbench.colorCustomizations": {
      "editorInlayHint.background": "#2d2d2d",
      "editorInlayHint.foreground": "#888888",
      "editorInlayHint.border": "#444444",
      "editorInlayHint.typeForeground": "#a89984",
      "editorInlayHint.parameterForeground": "#83a598"
    }
    
  • 字体与间距:配置字体类型、大小、粗细和内边距,示例:
    "editor.inlayHints.fontFamily": "Consolas",
    "editor.inlayHints.fontSize": 12,
    "editor.inlayHints.fontWeight": "normal",
    "editor.inlayHints.padding": {"left": 2, "right": 4}
    

3. 多层级设置调整

所有配置可在User或Workspace层级生效:

  • User Settings:按下Ctrl+,打开设置面板,搜索对应项修改,全局所有项目生效
  • Workspace Settings:在项目根目录的.vscode/settings.json中添加配置,仅对当前项目生效
  • 示例Workspace配置:
    {
      "editor.inlayHints.enabled": "on",
      "workbench.colorCustomizations": {
        "editorInlayHint.foreground": "#6699cc"
      },
      "editor.inlayHints.fontSize": 11
    }
    

内容的提问来源于stack exchange,提问作者David J.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 21:30:05