VSCode自定义快捷键和添加自定义快捷键按键到状态栏

news2025/5/23 1:42:43

VSCode自定义快捷键和添加自定义快捷键按键到状态栏


📄在VSCode中想实现快捷键方式执行某些指令操作,可以通过配置组合式的键盘按键映射来实现,另外一种方式就是将执行某些特定的指令嵌入在面板菜单上,在想要执行的时候,鼠标点击对应按键图标即可实现操作。

📘VSCode自定义快捷键方法

  • 打开命令面板(快捷键 Ctrl+Shift+P)。

  • 搜索并选择“Preferences: Open Keyboard Shortcuts (JSON)”。
    在这里插入图片描述

  • keybindings.json 文件中添加自定义快捷键,例如:我这里配置的是Raspberry Pi Pico插件中的SWD下载程序用的快捷键

// 将键绑定放在此文件中以覆盖默认值
[

{
    "key": "ctrl+shift+enter",
    "command": "raspberry-pi-pico.flashProject",
    "when": "raspberry-pi-pico.isPicoProject"
}
]


  • 对应的命令:
    在这里插入图片描述

当程序编译好后,可以直接使用快捷键进行程序烧录操作。

  1. “key”: “ctrl+shift+enter”
    含义:这部分定义了触发对应命令的快捷键组合。在 Windows 和 Linux 系统中,当用户同时按下 Ctrl、Shift 和 Enter 这三个键时,VS Code 会尝试执行与之绑定的命令。在 macOS 系统中,Ctrl 会对应为 Command 键(前提是未对 VS Code 的按键映射进行特殊修改)。
    用途:为用户提供了一种快速触发特定操作的方式,避免了通过菜单或命令面板来执行命令,提高了操作效率。
  2. “command”: “raspberry - pi - pico.flashProject”
    含义:指定了按下上述快捷键组合时要执行的具体命令。raspberry - pi - pico.flashProject 是一个特定的命令标识符,通常由扩展(这里是 Raspberry Pi Pico 扩展)定义。这个命令可能用于将项目代码烧录到 Raspberry Pi Pico 开发板上。
    用途:将快捷键与特定的功能操作关联起来,当用户按下指定快捷键时,VS Code 会查找并执行该命令对应的逻辑。
  3. “when”: “raspberry - pi - pico.isPicoProject”
    含义:这是一个条件表达式,用于指定在何种情况下该快捷键绑定才会生效。raspberry - pi - pico.isPicoProject 是一个由 Raspberry Pi Pico 扩展定义的上下文条件,只有当当前项目被识别为 Raspberry Pi Pico 项目时,按下 Ctrl + Shift + Enter 组合键才会触发 raspberry - pi - pico.flashProject 命令。
    用途:通过设置条件,可以避免在不相关的场景下误触发快捷键,提高快捷键使用的准确性和针对性。例如,如果当前打开的不是 Raspberry Pi Pico 项目,按下这个快捷键组合将不会执行烧录操作。
  • 需要执行的command可以在对应安装的插件目录里对应的package.json文件中找到所有命令的名称定义。这里以我的电脑安装的raspberry-pi-pico插件为例:
  • 插件安装位置:(以最新插件版本位置为准)
C:\Users\Administrator\.vscode\extensions\raspberry-pi.raspberry-pi-pico-0.17.4\package.json

在这里插入图片描述

  • 在成员对象(contributes)中,找到成员对应的命令(commands):
"contributes": {
		"commands": [
			{
				"command": "raspberry-pi-pico.newProject",
				"title": "New Pico Project",
				"category": "Raspberry Pi Pico"
			},
			{
				"command": "raspberry-pi-pico.switchSDK",
				"title": "Switch Pico SDK",
				"category": "Raspberry Pi Pico",
				"enablement": "raspberry-pi-pico.isPicoProject"
			},
			{
				"command": "raspberry-pi-pico.switchBoard",
				"title": "Switch Board",
				"category": "Raspberry Pi Pico",
				"enablement": "raspberry-pi-pico.isPicoProject"
			},
			{
				"command": "raspberry-pi-pico.launchTargetPath",
				"title": "Get path of the project executable",
				"category": "Raspberry Pi Pico",
				"enablement": "false"
			},
			{
				"command": "raspberry-pi-pico.getPythonPath",
				"title": "Get python path",
				"category": "Raspberry Pi Pico",
				"enablement": "false"
			},
			{
				"command": "raspberry-pi-pico.getEnvPath",
				"title": "Get environment path",
				"category": "Raspberry Pi Pico",
				"enablement": "false"
			},
			{
				"command": "raspberry-pi-pico.getGDBPath",
				"title": "Get GDB path",
				"category": "Raspberry Pi Pico",
				"enablement": "false"
			},
			{
				"command": "raspberry-pi-pico.getCompilerPath",
				"title": "Get compiler path",
				"category": "Raspberry Pi Pico",
				"enablement": "false"
			},
			{
				"command": "raspberry-pi-pico.getCxxCompilerPath",
				"title": "Get C++ compiler path",
				"category": "Raspberry Pi Pico",
				"enablement": "false"
			},
			{
				"command": "raspberry-pi-pico.getChip",
				"title": "Get Chip",
				"category": "Raspberry Pi Pico",
				"enablement": "false"
			},
			{
				"command": "raspberry-pi-pico.getChipUppercase",
				"title": "Get Chip Uppercase",
				"category": "Raspberry Pi Pico",
				"enablement": "false"
			},
			{
				"command": "raspberry-pi-pico.getTarget",
				"title": "Get OpenOCD Target",
				"category": "Raspberry Pi Pico",
				"enablement": "false"
			},
			{
				"command": "raspberry-pi-pico.getPicotoolPath",
				"title": "Get Picotool path",
				"category": "Raspberry Pi Pico",
				"enablement": "false"
			},
			{
				"command": "raspberry-pi-pico.compileProject",
				"title": "Compile Pico Project",
				"category": "Raspberry Pi Pico",
				"enablement": "raspberry-pi-pico.isPicoProject"
			},
			{
				"command": "raspberry-pi-pico.runProject",
				"title": "Run Pico Project (USB)",
				"category": "Raspberry Pi Pico",
				"enablement": "raspberry-pi-pico.isPicoProject"
			},
			{
				"command": "raspberry-pi-pico.clearGithubApiCache",
				"title": "Clear GitHub API cache",
				"category": "Raspberry Pi Pico"
			},
			{
				"command": "raspberry-pi-pico.conditionalDebugging",
				"title": "Conditional Debugging",
				"category": "Raspberry Pi Pico",
				"enablement": "raspberry-pi-pico.isPicoProject && !inQuickOpen"
			},
			{
				"command": "raspberry-pi-pico.debugLayout",
				"title": "Debug Layout",
				"category": "Raspberry Pi Pico",
				"enablement": "raspberry-pi-pico.isPicoProject"
			},
			{
				"command": "raspberry-pi-pico.openSdkDocumentation",
				"title": "Open SDK Documentation",
				"category": "Raspberry Pi Pico"
			},
			{
				"command": "raspberry-pi-pico.configureCmake",
				"title": "Configure CMake",
				"category": "Raspberry Pi Pico",
				"enablement": "raspberry-pi-pico.isPicoProject"
			},
			{
				"command": "raspberry-pi-pico.switchBuildType",
				"title": "Switch Build Type",
				"category": "Raspberry Pi Pico",
				"enablement": "raspberry-pi-pico.isPicoProject"
			},
			{
				"command": "raspberry-pi-pico.importProject",
				"title": "Import Pico Project",
				"category": "Raspberry Pi Pico"
			},
			{
				"command": "raspberry-pi-pico.newExampleProject",
				"title": "New Example Pico Project",
				"category": "Raspberry Pi Pico"
			},
			{
				"command": "raspberry-pi-pico.uninstallPicoSDK",
				"title": "Uninstall Pico SDK",
				"category": "Raspberry Pi Pico"
			},
			{
				"command": "raspberry-pi-pico.flashProject",
				"title": "Flash Pico Project (SWD)",
				"category": "Raspberry Pi Pico",
				"enablement": "raspberry-pi-pico.isPicoProject"
			},
			{
				"command": "raspberry-pi-pico.cleanCmake",
				"title": "Clean CMake",
				"category": "Raspberry Pi Pico",
				"enablement": "raspberry-pi-pico.isPicoProject && !raspberry-pi-pico.isRustProject"
			}
		],

在以上包含的成员-命令都可以设置对应的快捷键。

📗添加自定义快捷键按键到状态栏

有时候插件安装好后,在状态栏上没有我们所需要的快捷键按键图标,但是插件里面是带有有此快捷命令的,就可以自己添加。

添加方法

这里我还是以上面的raspberry-pi-pico插件中的SWD烧录快捷键命令图标,进行添加。

  • 找到插件安装目录,配置状态栏上内嵌的快捷键插件图标定义是在extension.cjs文件中。
C:\Users\Administrator\.vscode\extensions\raspberry-pi.raspberry-pi-pico-0.17.4\dist\extension.cjs
  • 搜索关键字StatusBarItemKey,定位到VSCode状态栏内嵌快捷键按键定义的地方。
var StatusBarItemKey;
(function (StatusBarItemKey) {
    StatusBarItemKey["compile"] = "raspberry-pi-pico.compileProject";
    StatusBarItemKey["run"] = "raspberry-pi-pico.runProject";
	StatusBarItemKey["swd"] = "raspberry-pi-pico.flashProject";/*添加自己想要的快捷键按键到VSCode状态栏上的指令*/
    StatusBarItemKey["picoSDKQuickPick"] = "raspberry-pi-pico.sdk-quick-pick";
    StatusBarItemKey["picoBoardQuickPick"] = "raspberry-pi-pico.board-quick-pick";
})(StatusBarItemKey || (StatusBarItemKey = {}));
const STATUS_BAR_ITEMS = {
    [StatusBarItemKey.compile]: {
        // alt. "$(gear) Compile"
        text: "$(file-binary) Compile",
        command: "raspberry-pi-pico.compileProject",
        tooltip: "Compile Project",
    },
    [StatusBarItemKey.run]: {
        // alt. "$(gear) Compile"
        text: "$(run) Run",
        command: "raspberry-pi-pico.runProject",
        tooltip: "Run Project",
    },
    /*添加自己想要的快捷键按键到VSCode状态栏上的指令*/
	    [StatusBarItemKey.SWD]: {
        // alt. "$(gear) Compile"
        text: "$(swd) SWD"
        command: "raspberry-pi-pico.flashProject",
        tooltip: "SWD Project",
    },
    [StatusBarItemKey.picoSDKQuickPick]: {
        text: "Pico SDK: <version>",
        command: "raspberry-pi-pico.switchSDK",
        tooltip: "Select Pico SDK",
    },
    [StatusBarItemKey.picoBoardQuickPick]: {
        text: "Board: <board>",
        command: "raspberry-pi-pico.switchBoard",
        tooltip: "Select Board",
    },
};
  1. 定义枚举类型 StatusBarItemKey
    var StatusBarItemKey;:声明一个变量 StatusBarItemKey,用于后续存储枚举对象。
    (function (StatusBarItemKey) {… })(StatusBarItemKey || (StatusBarItemKey = {}));:这是一个立即执行函数表达式(IIFE)。它的作用是创建一个局部作用域,避免变量污染全局作用域。
    StatusBarItemKey || (StatusBarItemKey = {}):如果 StatusBarItemKey 已经存在,则使用它;否则,将其初始化为一个空对象。
    在函数内部,为 StatusBarItemKey 对象添加了多个属性,这些属性作为枚举成员,每个成员都有一个对应的字符串值,这些值通常是 VSCode 命令的标识符。
  2. 定义状态栏项目对象 STATUS_BAR_ITEMS
    const STATUS_BAR_ITEMS = {... };:定义一个常量对象 STATUS_BAR_ITEMS,用于存储状态栏项目的详细信息。
    [StatusBarItemKey.compile]、[StatusBarItemKey.run] 等:使用计算属性名,将 StatusBarItemKey 枚举中的成员作为对象的属性名。
    每个属性对应一个对象,包含以下三个属性:
    text:状态栏项目显示的文本内容,$(...) 是 VSCode 的图标语法,用于在文本中显示图标。
    command:点击状态栏项目时要执行的 VSCode 命令的标识符。
    tooltip:鼠标悬停在状态栏项目上时显示的工具提示信息。
    总结
  • 其他插件的状态栏快捷键按键添加方法,应该也和这个类似,找到对应的StatusBarItemKey地方,按照现有的指令快捷键按键,依葫芦画瓢的方式补充添加即可。
  • 添加成功后,重启VSCode,打开对应的工程时,所添加的图标会显示在状态栏上:
    在这里插入图片描述

🛠自定义修改系统栏插件命令图标和内容

  • 🌿修改的属性内容:
 [StatusBarItemKey.SWD]: {
        // alt. "$(gear) Compile"
        text: "$(swd) SWD",
        command: "raspberry-pi-pico.flashProject",
        tooltip: "CMSIS-DAP Project",
    },
  • 🔬对应的状态栏图标显示内容效果:(tooltip属性值,影响鼠标移动到对应图标上所显示的内容提示信息)
    在这里插入图片描述
  • 🌿修改显示名称: text: "$(file-binary) Compile",修改为成: text: "$(file-binary) Build",
    [StatusBarItemKey.compile]: {
        // alt. "$(gear) Compile"
        text: "$(file-binary) Build",
        command: "raspberry-pi-pico.compileProject",
        tooltip: "Compile Project",
    },
  • 显示效果:(原来的Compile字符显示换成Build
    在这里插入图片描述
  • 🌟增加图标显示效果:(带图标显示效果的状态栏快捷键按键图标)
  [StatusBarItemKey.SWD]: {
        // alt. "$(gear) Compile"
        text: "$(debug-step-into) SWD",
        command: "raspberry-pi-pico.flashProject",
        tooltip: "CMSIS-DAP Project",
    },
  • 显示修改:(debug-step-into代表在SWD前面所显示的图标符号)
    在这里插入图片描述

📒显示或隐藏对应的插件快捷键图标方法:

在状态栏上右键,找到对应的插件扩展,前面打钩的选项就是显示出来的,没有打钩的就不会显示在状态栏上。可以很方便的管理状态栏上的显示快捷键,将一些不常用无关紧要的快捷功能按键图标隐藏掉,简洁VSCode状态栏显示界面。

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • 🎉显示图标其相关图标代码和对应图标的显示效果可以参考下面的网址:
https://code.visualstudio.com/api/references/icons-in-labels

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2302092.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Ubuntu22.04 - gflags的安装和使用

目录 gflags 介绍gflags 安装gflags 使用 gflags 介绍 gflags 是Google 开发的一个开源库&#xff0c;用于 C应用程序中命令行参数的声明、定义和解析。gflags 库提供了一种简单的方式来添加、解析和文档化命令行标志(flags),使得程序可以根据不同的运行时配置进行调整。 它具…

java | MyBatis-plus映射和golang映射对比

文章目录 Java实体类和数据库的映射1.默认驼峰命名规则2.自定义字段映射3.关闭驼峰命名规则4.JSON序列化映射 Golang1. 结构体与表的映射2. 字段与列的映射3. 关联关系映射4. 其他映射相关标签 这篇也是做数据库映射方面的对比&#xff1a; Java 实体类和数据库的映射 1.默认…

正则表达式–断言

原文地址&#xff1a;正则表达式–断言 – 无敌牛 欢迎参观我的个人博客&#xff1a;正则表达式特殊字符 – 无敌牛 断言assertions 1、(?...)&#xff1a;正向预查&#xff08;positive lookahead&#xff09;&#xff0c;表示某个字符串后面应该跟着什么。但这个字符串本身…

电脑想安装 Windows 11 需要开启 TPM 2.0 怎么办?

尽管 TPM 2.0 已经内置在许多新电脑中&#xff0c;但很多人并不知道如何激活这一功能&#xff0c;甚至完全忽略了它的存在。其实&#xff0c;只需简单的几步操作&#xff0c;你就能开启这项强大的安全特性&#xff0c;为你的数字生活增添一层坚固的防护屏障。无论你是普通用户还…

QT之改变鼠标样式

QT改变鼠标图片 资源路径如下 代码实现 QPixmap customCursorPixmap(":/images/mouse.png");QCursor customCursor(customCursorPixmap);QWidget::setCursor(customCursor); // 可以设置为整个窗口或特定控件QWidget::setCursor(); // 设置为透明光标&#xff0c…

ue----git局域网内部署裸仓库,别的机器进行访问

最近由于经常迁移项目到另一台机器上进行部署更新一点就要整个迁移 弄得麻烦了 就在网上学了一下这个方式 首先我们在想要建立裸仓库的电脑上找到一个文件夹放置我们的裸仓库 在此点击鼠标右键选择 open git bash here 输入命令 创裸仓库 git init --bare gitTestName.git…

PaddlePaddle的OCR模型转onnx-转rknn模型_笔记4

一、PaddlePaddle的OCR模型转onnx 1、首先建立一个新的虚拟环境 conda create -n ppocr python3.10 -y conda activate ppocr 2、进入paddlepaddle官网输入以下指令安装paddlepaddle GPU版本 &#xff08;我的cuda版本是11.8,根据你电脑装合适版本&#xff09; pip instal…

【大模型系列篇】DeepSeek-R1如何通过强化学习有效提升大型语言模型的推理能力?

如何通过强化学习&#xff08;RL&#xff09;有效提升大型语言模型&#xff08;LLM&#xff09;的推理能力&#xff1f; 《DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning》由DeepSeek-AI团队撰写&#xff0c;主要介绍了他们开发的第一代…

企业存储系统

一、概述 数字经济 人类通过大数据&#xff08;数字化的知识与信息&#xff09;的识别—选择—过滤—存储—使用&#xff0c;引导、实现资源的快速优化配置与再生&#xff0c;实现经济高质量发展的经济形态。 产业互联网推动发展 企业开始进行数字化转型&#xff0c;将传统…

数据结构系列一:初识集合框架+复杂度

前言 数据结构——是相互之间存在一种或多种特定关系的数据元素的集合。数据结构是计算机专业的基础课程&#xff0c;但也是一门不太容易学好的课&#xff0c;它当中有很多费脑子的东西&#xff0c;之后在学习时&#xff0c;你若碰到了困惑或不解的地方 都是很正常的反应&…

Linux系统编程学习 NO.14——缓冲区的概念、模拟实现Cstdio库

用户缓冲区 先介绍一下关于用户缓冲区的周边知识。 fread和fwrite的返回值 谈一谈fread和fwrite的返回值&#xff0c;如果写入/读取文件成功&#xff0c;fread或fwrite的返回值指的是实际写入/读取的内存块数量(实际的nmemb的大小)。假如fwrite写入的size是5字节&#xff0c;…

某手sig3-ios算法 Chomper黑盒调用

Chomper-iOS界的Unidbg 最近在学习中发现一个Chomper框架&#xff0c;Chomper 是一个模拟执行iOS可执行文件的框架&#xff0c;类似于安卓端大名鼎鼎的Unidbg。 这篇文章使用Chomper模拟执行某手的sig3算法&#xff0c;初步熟悉该框架。这里只熟悉模拟执行步骤以及一些常见的…

MySQL版本选择与安装

MySQL版本选择与安装 MySQL 5.5 优点: 稳定性&#xff1a;5.5版本是长期支持&#xff08;LTS&#xff09;版本&#xff0c;因此它非常稳定&#xff0c;被广泛部署在生产环境中。 兼容性&#xff1a;与旧版本的MySQL和各种应用程序有很好的兼容性。 缺点: 过时&#xff1a;…

【飞行器原理学习】——1. 机翼及机翼参数

飞行器原理学习——1.机翼 一、 概述 飞机的各种机翼是飞机的控制面 通过铰链、钢索、液压等方式连接在机身上 操纵面运动时&#xff0c;会改变机翼的弧度和形状&#xff0c;使流经的空气发生偏转&#xff0c;从而影响空气动力的大小。使飞机围绕着3轴运动 二、机翼的操纵面…

TS语言自定义脚手架

初始化 新建文件夹初始化命令 npm init -ytsc --initnpm i types/nodenpm i typescript# 处理别名npm i -D tsc-alias -y 表示选项都为yes 安装ts相关依赖 新建相关文件 bin 文件夹 src文件夹 commands 文件夹 &#xff08;命令 utils 文件夹 (封装方法&#xff09; index.t…

lab4 CSAPP:Cachelab

写在前面 最简单的一集 实验室分为两个部分。在A部分中&#xff0c;实现一个缓存模拟器。在B部分中&#xff0c;编写一个矩阵针对高速缓存性能优化的转置功能。 感觉是比较经典的问题&#xff0c;之前在体系结构的课程中接触过&#xff0c;终于能通过lab实操一下了。 实验目…

VScode C语言学习开发环境;运行提示“#Include错误,无法打开源文件stdio.h”

C/C环境配置 参考&#xff1a; VS Code 配置 C/C 编程运行环境&#xff08;保姆级教程&#xff09;_vscode配置c环境-CSDN博客 基本步骤 - 安装MinGW-W64&#xff0c;其包含 GCC 编译器&#xff1a;bin目录添加到环境变量&#xff1b;CMD 中输入gcc --version或where gcc验证…

雷龙CS SD NAND(贴片式TF卡)测评体验

声明&#xff1a;非广告&#xff0c;为用户体验文章 前段时间偶然获得了雷龙出品的贴片式 TF 卡芯片及转接板&#xff0c;到手的是两片贴片式 nand 芯片搭配一个转接板&#xff0c;其中有一片官方已经焊接好了&#xff0c;从外观来看&#xff0c;正面和背面设计布局合理&#x…

伯克利 CS61A 课堂笔记 11 —— Mutability

本系列为加州伯克利大学著名 Python 基础课程 CS61A 的课堂笔记整理&#xff0c;全英文内容&#xff0c;文末附词汇解释。 目录 01 Objects 02 Example: Strings Ⅰ Representing Strings: the ASCII Standard Ⅱ Representing Strings: the Unicode Standard 03 Mutatio…

DEX-EE三指灵巧手:扩展AI与机器人研究的边界

DEX-EE三指灵巧手&#xff0c;由Shadow Robot与Google DeepMind合作开发&#xff0c;以其先进技术和设计&#xff0c;正在引领AI与机器人研究的新趋势。其高精度传感器和灵活的机械手指&#xff0c;能够捕捉复杂的环境数据&#xff0c;为强化学习实验提供了可靠支持。 Shadow R…