VSCode Profile Switcher
VSCode Profile Switcher 是一个 VSCode 扩展,可以根据不同的条件自动切换 VSCode 配置文件(Profile)。
功能特性
- 根据打开的文件夹自动切换配置文件
- 根据工作区文件自动切换配置文件
- 根据打开的文件扩展名自动切换配置文件
- 可通过状态栏手动切换配置文件
- 支持通过配置规则自定义切换逻辑
Preview
GIF
GIF's Config
"profileSwitcher.rules": [
{
"profile": "python",
"fileExts": ["py"]
},
{
"profile": "test",
"fileExts": ["bat"]
}
]
使用方法
Steps
- 确保在所有需要的配置文件上安装此扩展, 或者把扩展设置为"将扩展应用于所用配置文件".
- 设置中搜索
profileSwitcher.rules,将其设置为"将设置应用于所有配置文件".
- 命令面板中输入
open app setting json ,选择Preferences: Open Application Settings(Json) 命令,
将打开默认Profile的settings.json.
- 接下来在默认Profile的
settings.json中配置 profileSwitcher.rules
- 命令面板输入
Gen template ,选择Profiles: Generate template 命令生成配置模板文件.
- 根据需要修改模版, 再复制到
settings.json.
[!Note]
模板是通过读取你创建的所有配置文件的名称生成的(不包括默认配置), 不需要的选项可以删除.
- 扩展会根据配置的规则以及打开的vscode窗口的工作区状态自动切换配置文件.
配置选项
Options
在 VSCode 设置中可以配置 profileSwitcher.rules,规则包含以下字段:
profile: 配置文件名称
folders: 指定文件夹,当打开这些指定文件夹下的子文件夹时使用指定的配置文件. 优先级最高.
projectManifestFile: 使用文件匹配模式,当工作区包含匹配的不同编程语言特有的项目清单文件(比如Cargo.toml,package.json)时使用指定的配置文件.
此选项比通用的pattern选项优先级更高.
pattern: 使用文件匹配模式,当工作区包含匹配的文件时使用指定的配置文件.
fileExts: 根据文件扩展名切换配置文件. 只在窗口没有工作区打开但打开了文本文档时切换一次, 窗口内没有文档打开时计数归零.
命令
Profiles: Gen template: 生成配置模板文件
Profiles: Reload configuration: 重新加载配置(当更改vscode配置文件即profiles后使用)
English
VSCode Profile Switcher is a VSCode extension that automatically switches VSCode profiles based on different conditions.
Features
- Automatically switch profiles based on opened folders
- Automatically switch profiles based on workspace files
- Automatically switch profiles based on opened file extensions
- Manually switch profiles via status bar
- Support custom switching logic through configuration rules
Usage
Steps
- Make sure to install this extension on all the profiles you need, or set the extension to "Apply extension to all profiles".
- In settings, search for
profileSwitcher.rules and set it to "Apply setting to all profiles".
- In the command palette, enter
open app setting json, select the Preferences: Open Application Settings(Json) command, which will open the settings.json of the default Profile.
- Next, configure
profileSwitcher.rules in the settings.json of the default Profile
- In the command palette, enter
Gen template, select the Profiles: Generate template command to generate a configuration template file.
- Modify the template as needed, then copy to
settings.json.
[!Note]
The template is generated by reading all the profile names you created (excluding the default profile), and options you don't need can be deleted.
- The extension will automatically switch profiles based on the configured rules and the workspace state of the opened vscode window.
Configuration Options
In VSCode settings, you can configure profileSwitcher.rules with the following fields:
profile: Profile name
folders: Specify folders, when subfolders under these specified folders are opened, use the specified profile. Highest priority.
projectManifestFile: Use file matching patterns, when the workspace contains matching project manifest files specific to different programming languages (such as Cargo.toml, package.json), use the specified profile.
This option has higher priority than the generic pattern option.
pattern: Use file matching patterns, when the workspace contains matching files, use the specified profile
fileExts: Switch profiles based on file extensions. Switches only once when the window has no workspace open but a text document is opened, and the count resets when no document is open in the window.
Commands
Profiles: Gen template: Generate configuration template file
Profiles: Reload configuration: Reload configuration (use after changing vscode profiles)
Thank
Part of the code comes from the following projects
robole/vscode-profile-status
CrendKing/vscode-auto-profile-switcher
| |