配置VScode终端

本文介绍了如何配置VScode的终端,包括更改选项卡位置、拆分终端、自定义标签,以及配置终端配置文件。此外,还讲解了如何修改settings.json文件添加自定义背景图片,解决Code损坏和运行代码显示已运行的问题。
摘要由CSDN通过智能技术生成

终端管理

设置更改选项卡位置

使用terminal.integrated.tabs.location设置更改选项卡位置

"terminal.integrated.tabs.location" :"right"

在这里插入图片描述

拆分终端

通过以下方式拆分终端:

  • 在悬停时,选择内联拆分按钮。
  • 右键单击上下文菜单并选择拆分菜单选项。
  • Alt单击选项卡、+按钮或终端面板上的单个选项卡。
  • 使用Ctrl+Shift+5命令。
    在这里插入图片描述

自定义标签

通过右键单击上下文菜单或触发以下命令来更改终端的名称、图标和选项卡颜色:
在这里插入图片描述

终端:重命名	workbench.action.terminal.rename
终端:更改图标 workbench.action.terminal.changeIcon
终端:改变颜色 workbench.action.terminal.changeColor

终端配置文件

终端配置文件是特定于平台的 shell 配置,由可执行路径、参数和其他自定义组成。

示例配置文件:

{
  "terminal.integrated.profiles.windows": {
    "My PowerShell": {
      "path": "pwsh.exe",
      "args": ["-noexit", "-file", "${env:APPDATA}PowerShellmy-init-script.ps1"]
    }
  },
  "terminal.integrated.defaultProfile.windows": "My PowerShell"
}

您可以在终端配置文件中使用变量,如上面示例中所示,以及APPDATA环境变量。您可以在变量参考主题中找到可用变量的列表。

通过运行终端配置您的默认集成终端:选择默认配置文件命令,该命令也可通过终端下拉菜单访问
在这里插入图片描述
终端的 shell在 Linux 和 macOS 上默认为$SHELL,Windows 上默认为 PowerShell。VS Code 将自动检测大多数标准 shell,然后可以将其配置为默认值。

配置配置文件

可以使用path或source以及一组可选参数创建配置文件。source仅适用于Windows,可以用来让VS代码检测安装的任何PowerShell或Git Bash。path可以使用直接指向 shell 可执行文件。以下是一些示例配置文件配置:

{
  "terminal.integrated.profiles.windows": {
    "PowerShell -NoProfile": {
      "source": "PowerShell",
      "args": ["-NoProfile"]
    }
  },
  "terminal.integrated.profiles.linux": {
    "zsh (login)": {
      "path": "zsh",
      "args": ["-l"]
    }
  }
}

配置文件中支持的其他参数包括:

  • overrideName:一个布尔值,指示是否用静态配置文件名称替换检测正在运行的程序的动态终端标题。
  • env: 定义环境变量及其值的映射,将变量设置null为将其从环境中删除。这可以使用terminal.integrated.env.设置为所有配置文件配置。
  • icon:用于配置文件的图标 ID。
  • color:用于设置图标样式的主题颜色 ID。

提示: path、args、env都支持解析变量

该默认配置文件可以手动与定义terminal.integrated.defaultProfile.*设置。这应该设置为现有配置文件的名称:

{
  "terminal.integrated.profiles.windows": {
    "my-pwsh": {
      "source": "PowerShell",
      "args": ["-NoProfile"]
    }
  },
  "terminal.integrated.defaultProfile.windows": "my-pwsh"
}

提示:集成终端外壳在 VS Code 的权限下运行。如果您需要使用提升的(管理员)权限或不同的权限运行 shell 命令,请使用平台实用程序,例如runas.exe在终端中。

删除内置配置文件

要从终端下拉列表中删除条目,请将配置文件的名称设置为null。例如,要删除Git Bash Windows 上的配置文件,请使用以下设置:

{
  "terminal.integrated.profiles.windows": {
    "Git Bash": null
  }
}

其他请阅读

VScode终端

修改settings.json文件

{
    "KeilAssistant.MDK.Uv4Path": "E:\\keil\\??\\UV4\\UV4.exe",
    "C_Cpp.updateChannel": "Insiders",
    "files.autoGuessEncoding": true,
    "http.proxySupport": "off",
    "workbench.iconTheme": "material-icon-theme",
    "cmake.configureOnOpen": true,
    "workbench.editorAssociations": {
        "*.ipynb": "jupyter-notebook"
    },
    "notebook.cellToolbarLocation": {
        "default": "right",
        "jupyter-notebook": "left"
    },
    //"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    //"terminal.integrated.defaultProfile.windows": "Command Prompt",
    //"terminal.integrated.defaultProfile.windows": "PowerShell",

        "terminal.integrated.profiles.windows": {
            "PowerShell": {
              "source": "PowerShell",
              //"path": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
              "color": "terminal.ansiBlue"
            },

            "gitBash": {
                "path": "E:\\Git\\Git\\bin\\bash.exe",
                "color": "terminal.ansiYellow"
            },

            "cmd": {
                "path": "C:\\WINDOWS\\System32\\cmd.exe",
                "color": "terminal.ansiRed",
                "icon": "account",
                //"workbench.action.terminal.changeColor":"terminal.ansiYellow"
            }
          },

        "terminal.integrated.defaultProfile.windows": "PowerShell",
        "terminal.integrated.tabs.location" :"right"
        
}

在这里插入图片描述

添加自定义背景图片

先在vscode里面下载扩展插件“background”,默认会有一张背景图,也可以自己定义在这里插入图片描述
找到并打开打开settings.json
在这里插入图片描述
添加如下代码

//background 的相关配置
"update.enableWindowsBackgroundUpdates": true,
"background.customImages": [
	    //本地图片的位置,唯一需要改的地方
    "E:\\vscode\\picture",
    //"C:/Users/hp/Pictures/Camera Roll/2.jpg"
],
"background.style": 
    {
    "content":"''",
    "pointer-events":"none",
    "position":"absolute",//图片位置
    "width":"100%",
    "height":"120%",
    "z-index":"99999",
    "background.repeat":"repeat-Y",
    "background-size":"cover",//图片大小
    "opacity": 0.2 //透明度
},
"background.useFront": true,
"background.useDefault": false,
"editor.fontSize": 21, //是否使用默认图片

settings.json代码

{
    "KeilAssistant.MDK.Uv4Path": "E:\\keil\\??\\UV4\\UV4.exe",
    "C_Cpp.updateChannel": "Insiders",
    "files.autoGuessEncoding": true,
    "http.proxySupport": "off",
    "workbench.iconTheme": "material-icon-theme",
    "cmake.configureOnOpen": true,
    "workbench.editorAssociations": {
        "*.ipynb": "jupyter-notebook"
    },
    "notebook.cellToolbarLocation": {
        "default": "right",
        "jupyter-notebook": "left"
    },
    //"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    //"terminal.integrated.defaultProfile.windows": "Command Prompt",
    //"terminal.integrated.defaultProfile.windows": "PowerShell",

        "terminal.integrated.profiles.windows": {
            "PowerShell": {
              "source": "PowerShell",
              //"path": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
              "color": "terminal.ansiBlue"
            },

            "gitBash": {
                "path": "E:\\Git\\Git\\bin\\bash.exe",
                "color": "terminal.ansiYellow"
            },

            "cmd": {
                "path": "C:\\WINDOWS\\System32\\cmd.exe",
                "color": "terminal.ansiRed",
                "icon": "account",
                //"workbench.action.terminal.changeColor":"terminal.ansiYellow"
            }
          },

        "terminal.integrated.profiles.linux": {
            "Ubuntu-bash": {
                "path": "/bin/bash",
                "color": "terminal.ansiGreen",
                "icon": "thumbsup",
                //"workbench.action.terminal.changeColor":"terminal.ansiYellow"
            }  
          },

        "terminal.integrated.defaultProfile.windows": "PowerShell",
        "terminal.integrated.tabs.location": "right",
        "terminal.integrated.defaultProfile.linux": "Ubuntu-bash",


            //background 的相关配置
            "update.enableWindowsBackgroundUpdates": true,
            "background.customImages": [
                    //本地图片的位置,唯一需要改的地方
                "E:\\vscode\\picture",
                //"C:/Users/hp/Pictures/Camera Roll/2.jpg"
            ],
            "background.style": 
                {
                "content":"''",
                "pointer-events":"none",
                "position":"absolute",//图片位置
                "width":"100%",
                "height":"120%",
                "z-index":"99999",
                "background.repeat":"repeat-Y",
                "background-size":"cover",//图片大小
                "opacity": 0.2 //透明度
            },
            "background.useFront": true,
            "background.useDefault": false,
            "editor.fontSize": 21,
            "bracketPairColorizer.depreciation-notice": false, //是否使用默认图片
            
}

报错:Code安装似乎损坏,请重新安装

接着上面的步骤,修改完重启vscode,直接给code玩坏了
在这里插入图片描述
此时需要安装Fix VSCode Checksums插件
在这里插入图片描述
Ctrl+Shift+P , 输入Fix Checksums:Apply(注意冒号是英文的),点击,重启即可,记住需要在本地打开(Windows上)的VSCode中搜索
在这里插入图片描述
在这里插入图片描述
在连接了WSL的VSCode中可能找不到Fix Checksums:Apply,或者会报错
在这里插入图片描述
重启后可以了,但是图片加载不出来,把图片路径修改如下
在这里插入图片描述
修改后保存重启就可以了,有一点不好就是每次修改后都会造成code损坏的报错,需要Ctrl+Shift+P,输入Fix Checksums :Apply,点击,重启
在这里插入图片描述
最后我想背景图全屏显示,于是修改settings.json
在这里插入图片描述
修改后的settings.json代码

{
    "KeilAssistant.MDK.Uv4Path": "E:\\keil\\??\\UV4\\UV4.exe",
    "C_Cpp.updateChannel": "Insiders",
    "files.autoGuessEncoding": true,
    "http.proxySupport": "off",
    "workbench.iconTheme": "material-icon-theme",
    "cmake.configureOnOpen": true,
    "workbench.editorAssociations": {
        "*.ipynb": "jupyter-notebook"
    },
    "notebook.cellToolbarLocation": {
        "default": "right",
        "jupyter-notebook": "left"
    },
    //"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    //"terminal.integrated.defaultProfile.windows": "Command Prompt",
    //"terminal.integrated.defaultProfile.windows": "PowerShell",

        "terminal.integrated.profiles.windows": {
            "PowerShell": {
              "source": "PowerShell",
              //"path": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
              "color": "terminal.ansiBlue"
            },

            "gitBash": {
                "path": "E:\\Git\\Git\\bin\\bash.exe",
                "color": "terminal.ansiYellow"
            },

            "cmd": {
                "path": "C:\\WINDOWS\\System32\\cmd.exe",
                "color": "terminal.ansiRed",
                "icon": "account",
                //"workbench.action.terminal.changeColor":"terminal.ansiYellow"
            }
          },

        "terminal.integrated.profiles.linux": {
            "Ubuntu-bash": {
                "path": "/bin/bash",
                "color": "terminal.ansiGreen",
                "icon": "thumbsup",
                //"workbench.action.terminal.changeColor":"terminal.ansiYellow"
            }  
          },

        "terminal.integrated.defaultProfile.windows": "PowerShell",
        "terminal.integrated.tabs.location": "right",
        "terminal.integrated.defaultProfile.linux": "Ubuntu-bash",
        //"bracketPairColorizer.depreciation-notice": false,
        
            //background 的相关配置
            "update.enableWindowsBackgroundUpdates": true,
            "background.customImages": [
                    //本地图片的位置,唯一需要改的地方
                "file:///E:/vscode/picture/1.JPG",
                //"C:/Users/hp/Pictures/Camera Roll/2.jpg"
            ],
            "background.style": 
                {
                "content":"''",
                "pointer-events":"none",
                "position":"fixed",//图片位置居中
                "width":"100%",
                "height":"120%",
                "z-index":"99999",
                "top":"0px",
                "left":"0px",
                "background.repeat":"no-repeat",
                "background-size":"cover",//图片大小为全屏
                "opacity": 0.2 //透明度
            },
            "background.useFront": true,
            "background.useDefault": false,
            //"editor.fontSize": 21,
            "bracketPairColorizer.depreciation-notice": false, //是否使用默认图片
        
}

在这里插入图片描述

VScode运行代码显示:Code is already running

如果程序不会自动退出,而是显示代码一直运行,可以通过下面的解决方案退出程序:切换到OUTPUT(输出),点击tab,再点鼠标右键,然后选择stop code run
在这里插入图片描述
在这里插入图片描述

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只嵌入式爱好者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值