简体   繁体   English

有什么方法可以在实例之间同步我的 Visual Studio Code 设置?

[英]Is there any way to sync my Visual Studio Code settings between instances?

I'd like to be able to sync my VS Code user settings (File > Preferences > User Settings) to the cloud somehow so I can easily share them between multiple installations, as in Windows 10 and Visual Studio.我希望能够以某种方式将我的 VS Code 用户设置(文件 > 首选项 > 用户设置)同步到云,以便我可以轻松地在多个安装之间共享它们,就像在 Windows 10 和 Visual Studio 中一样。

Is there a supported way of doing this?有没有支持的方法来做到这一点? Direct support in Code would be great, but otherwise being able to move my settings.json location to a Dropbox or OneDrive folder would work too. Code 中的直接支持会很棒,但除此之外,能够将我的 settings.json 位置移动到 Dropbox 或 OneDrive 文件夹也可以。

I'm looking specifically for a way of doing this automatically and silently.我正在专门寻找一种自动且无声地执行此操作的方法。 Manually exporting/importing is too cumbersome and isn't what I'm looking for.手动导出/导入太麻烦,不是我想要的。


Update: this is now a built-in feature in VS Code .更新:这现在是VS Code内置功能

I have developed an extension that will sync all your Visual Studio Code Settings across multiple instances.我开发了一个扩展,可以跨多个实例同步所有 Visual Studio Code 设置。

Key Features主要特点

  1. Use your GitHub account token.使用您的 GitHub 帐户令牌。
  2. Easy to Upload and Download on one click.一键轻松上传和下载。
  3. Saves all settings and snippets files.保存所有设置和片段文件。
  4. Upload Key : Shift + Alt + u上传键:Shift + Alt + u
  5. Download Key : Shift + Alt + d下载键:Shift + Alt + d
  6. Type Sync In Order to View all sync options键入同步以查看所有同步选项

It Sync它同步

  • Settings File设置文件
  • Keybinding File键绑定文件
  • Launch File启动文件
  • Snippets Folder片段文件夹
  • VSCode Extensions VSCode扩展

Detail Documentation Source详细文档来源

VSCode - Settings Sync blog post VSCode - 设置同步博客文章

Download here : VS Code - Settings Sync - Extention在此处下载: VS Code - 设置同步 - 扩展

You can make a hard link from the directory containing user settings to your sync directory of applications such as Dropbox or OneDrive.您可以从包含用户设置的目录到您的应用程序(例如 Dropbox 或 OneDrive)的同步目录建立硬链接。

For example, on windows, the user settings are located in %APPDATA%\\Code\\User , so you could type:例如,在 Windows 上,用户设置位于%APPDATA%\\Code\\User ,因此您可以键入:

mklink /H /JX:\\Your\\Sync\\Dir %APPDATA%\\Code\\User

on your computers with Visual Studio Code to achieve the synchronization.在您的计算机上使用 Visual Studio Code 实现同步。

Then, on another computer, you may delete the %APPDATA%\\Code\\User folder, and type:然后,在另一台计算机上,您可以删除%APPDATA%\\Code\\User文件夹,然后键入:

mklink /H /J %APPDATA%\\Code\\User X:\\Your\\Sync\\Dir

to retrieve the synchronized settings.以检索同步设置。

Aha, you can try my VSCode extension: Syncing .啊哈,你可以试试我的 VSCode 扩展: 同步

Hoping you'll like it.希望你会喜欢。 :) :)


A Quick Guide快速指南

  1. Install Syncing :安装同步

  2. Get your own GitHub Personal Access Token :获取您自己的GitHub Personal Access Token

    1. Login to your GitHub Settings page.登录到您的GitHub Settings页面。

      登录设置页面

    2. Select Personal access tokens tab and click Generate new token .选择Personal access tokens选项卡,然后单击Generate new token

      生成新令牌

    3. Select gist and click Generate token .选择gist并单击Generate token

      允许要点

    4. Copy and backup your token.复制并备份您的令牌。

      复制和备份令牌

  3. Sync your settings:同步您的设置:

    Syncing will ask for necessary information for the first time and save for later use . Syncingfor the first time询问必要的信息并save for later use

    1. Upload :上传

      1. Type upload in VSCode Command Palette .VSCode Command PaletteVSCode Command Palette upload

      2. Enter your GitHub Personal Access Token .输入您的GitHub Personal Access Token

      3. Enter your Gist ID (or leave it blank to create automatically).输入您的Gist ID (或leave it blank以自动创建)。

      4. Done!完毕!

      5. After uploading, you can find your settings and the corresponding Gist ID in your GitHub Gist .上传后,您可以在您的GitHub Gist 中找到您的设置和相应的Gist ID

        设置和要点

    2. Download :下载

      1. Type download in VSCode Command Palette .VSCode Command PaletteVSCode Command Palette download

      2. Enter your GitHub Personal Access Token (or leave it blank if you want to download from a public Gist)输入您的GitHub Personal Access Token (如果您想从公共 Gist 下载,则将leave it blank

      3. Enter your Gist ID (or a public Gist ID ).输入您的Gist ID (或public Gist ID )。

      4. Done!完毕!

In v1.48:在 v1.48 中:

Preview features预览功能

Preview features are not ready for release but are functional enough to use.预览功能尚未准备好发布,但功能足以使用。 We welcome your early feedback while they are under development.我们欢迎您在开发过程中尽早提供反馈。

Settings Sync设置同步

Settings Sync is now available for preview in the stable release 🎉.设置同步现在可以在稳定版本中预览 🎉。 Refer to the user guide for more information & FAQs.有关更多信息和常见问题解答,请参阅用户指南

Feature is now called Settings Sync also in the product.该功能现在在产品中也称为设置同步 All of its references & settings are renamed to be aligned.它的所有参考和设置都被重命名为对齐。

Also see "Manual merge" and syncing between Insiders and Stable at https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_48.md#settings-sync另请参阅https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_48.md#settings-sync 上的“手动合并”和 Insiders 和 Stable 之间的同步


In v1.45 it looks like you will be able to login to the built-in Settings Sync via github, see https://github.com/microsoft/vscode/issues/95160#event-3266867554 (Support GitHub logins in settings sync).在 v1.45 中,您似乎可以通过 github 登录到内置设置同步,请参阅https://github.com/microsoft/vscode/issues/95160#event-3266867554 (在设置同步中支持 GitHub 登录)。 And the v1.45 Release Notes .v1.45 发行说明


In v1.43 as a preview feature (so in the Insiders' Build only) is settings sync .在 v1.43 中作为预览功能(因此仅在 Insiders' Build 中)是settings sync See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_43.md#settings-sync请参阅https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_43.md#settings-sync

Settings Sync设置同步

We have been working the last couple of months to support synchronizing VS Code settings, extensions, and keyboard shortcuts across machines (popular feature request #2743 ).过去几个月我们一直在努力支持跨机器同步 VS Code 设置、扩展和键盘快捷键(流行功能请求#2743 )。 In this milestone, we are happy to announce that this feature is ready for preview from our next 1.44.0-insider release.在这个里程碑中,我们很高兴地宣布此功能已准备好从我们的下一个1.44.0 内部版本中预览。 You can now have your customizations synchronized in all your VS Code installs across all your machines.您现在可以在所有机器上的所有 VS Code 安装中同步您的自定义。 You can also bootstrap VS Code with your personal customizations on a fresh machine with minimal effort.您还可以轻松地在新机器上使用您的个人定制引导 VS Code。 Following video demonstrates this:以下视频演示了这一点:

Supports detecting conflicts in settings and keybindings while synchronizing.支持在同步时检测设置和键绑定中的冲突。 Conflicts are shown using the diff editor with incoming (cloud) changes on the left side and local changes on the right side.使用差异编辑器显示冲突,左侧是传入(云)更改,右侧是本地更改。 You can resolve the conflicts by editing in the right side editor and merge the changes using the actions provided in the editor.您可以通过在右侧编辑器中进行编辑来解决冲突,并使用编辑器中提供的操作合并更改。

Supported Features支持的功能

Currently Settings, Keyboard Shortcuts, Extensions, and the Display Language are synchronized but we are planning to add more.目前设置、键盘快捷键、扩展和显示语言是同步的,但我们计划添加更多。 You can review our list of proposed Setting Sync features .您可以查看我们建议的设置同步功能列表。

Machine settings (with machine or machine-overridable scopes) are not synchronized by default.默认情况下,机器设置(具有机器或机器可覆盖范围)不同步。 You can also add or remove settings you want to this list from settings editor or using the setting sync.ignoredSettings .您还可以从设置编辑器或使用设置sync.ignoredSettings在此列表中添加或删除您想要的设置。

Keyboard Shortcuts are synchronized per platform by default.默认情况下,键盘快捷键按平台同步。 If your keyboard shortcuts are platform agnostic then, you can synchronize them across platforms by disabling the setting sync.keybindingsPerPlatform .如果您的键盘快捷键与平台无关,那么您可以通过禁用设置sync.keybindingsPerPlatform跨平台同步它们。

All built-in and installed extensions are synchronized along with their global enablement state.所有内置和安装的扩展与其全局启用状态同步。 You can skip synchronizing an extension, from extensions view or using the setting sync.ignoredExtensions .您可以从扩展视图或使用设置sync.ignoredExtensions跳过同步扩展。

Settings Sync activity can be monitored in the Log (Sync) output view.设置 同步活动可以在日志(同步)输出视图中进行监控。 All local customizations are backed up for last 30 days (atleast 10) in the disk whenever they are changed during synchronization.同步期间更改时,所有本地自定义项都会在磁盘中备份最近 30 天(至少 10 天)。 You can use the command Sync: Open Local Backups Folder to go the backups location and retain your old customizations.您可以使用命令同步:打开本地备份文件夹转到备份位置并保留旧的自定义设置。

(and a few gifs at the release note link) (以及发行说明链接中的一些 gif)

Note that is working through your Microsoft account , not github (until v1.45 - see top):请注意,这是通过您的 Microsoft 帐户,而不是 github(直到 v1.45 - 见顶部):

Settings Sync uses a Microsoft account to store your VS Code customizations for synchronization and therefore you would need an account to use this. Settings Sync 使用 Microsoft 帐户来存储用于同步的 VS Code 自定义,因此您需要一个帐户才能使用它。 Refer to the Settings Sync documentation for more information and help.有关更多信息和帮助,请参阅设置同步文档

Also see https://github.com/microsoft/vscode-docs/blob/vnext/docs/editor/settings-sync.md for more on how to set up settings sync .另请参阅https://github.com/microsoft/vscode-docs/blob/vnext/docs/editor/settings-sync.md有关如何设置settings sync


And a link to v1.44 info on Settings Sync: https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_44.md#settings-sync以及关于设置同步的 v1.44 信息的链接: https : //github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_44.md#settings-sync

I did this on my Mac by copying VS Code's settings.json to my iCloud drive for automatic backup, and then creating a symbolic link.我通过将 VS Code 的settings.json复制到我的 iCloud 驱动器进行自动备份,然后创建一个符号链接,在我的 Mac 上做到了这一点。

  1. Copy settings.json from VS code settings directory $HOME/Library/Application Support/Code/User/settings.json to your backup locationsettings.jsonVS 代码设置目录$HOME/Library/Application Support/Code/User/settings.json复制到您的备份位置
  2. Backup the old settings.json by renaming to settings-old.json通过重命名为settings-old.json来备份旧的settings.json
  3. In the terminal, cd to VS code setting dir: cd ~/Library/Application\\ Support/Code/User/在终端, cd到VS代码设置目录: cd ~/Library/Application\\ Support/Code/User/
  4. Create the symlink to your backed up file using command ln -sf path/to/backup/settings.json settings.json .使用命令ln -sf path/to/backup/settings.json settings.json创建指向备份文件的符号链接。 Since I backed mine up to iCloud and renamed the file to vscode.settings.json , my command looked like this: ln -sf ~/Library/Mobile\\ Documents/com~apple~CloudDocs/vscode.settings.json settings.json由于我将我的备份到 iCloud 并将文件重命名为vscode.settings.json ,我的命令如下所示: ln -sf ~/Library/Mobile\\ Documents/com~apple~CloudDocs/vscode.settings.json settings.json
  5. Check that you can open up user preferences in VS Code检查您是否可以在 VS Code 中打开用户首选项

To use the backup on a different Mac, just repeat steps 2-5.要在不同的 Mac 上使用备份,只需重复步骤 2-5。

I also did this for extensions ...我也为扩展做了这个......

cd ~/.vscode/
mkdir ~/Library/Mobile\ Documents/com~apple~CloudDocs/vscode/
cp -a extensions ~/Library/Mobile\ Documents/com~apple~CloudDocs/vscode
mv extensions extensions-old
ln -sf ~/Library/Mobile\ Documents/com~apple~CloudDocs/vscode/extensions extensions

Another way of doing it would be to soft link your files, which can also be stored in a repository on GitHub.另一种方法是软链接您的文件,这些文件也可以存储在 GitHub 上的存储库中。 For example, on Mac OS let's say you have a directory called ~/dev/dotfiles/vscode .例如,在 Mac OS 上,假设您有一个名为~/dev/dotfiles/vscode Let's say there are two files in there called settings.json and keybindings.json .假设那里有两个文件,名为settings.jsonkeybindings.json You could soft link these files with:您可以将这些文件软链接到:

ln -s ~/dev/dotfiles/vscode/keybindings.json ~/Library/Application\ Support/Code/User/keybindings.json
ln -s ~/dev/dotfiles/vscode/settings.json ~/Library/Application\ Support/Code/User/settings.json

If you are using Windows or Linux the path to the respective settings directories can be found at https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations如果您使用的是 Windows 或 Linux,则可以在https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations找到相应设置目录的路径

I place my settings.json in a configuration file that I sync with git (though Dropbox would also work) and use a Python script to symlink it to the correct location for each platform so updating it from the settings menu syncs across my machines.我将我的settings.json放在我与 git 同步的配置文件中(尽管 Dropbox 也可以工作)并使用 Python 脚本将它符号链接到每个平台的正确位置,以便从设置菜单更新它在我的机器上同步。 Creating symlinks requires admin privileges on Windows.创建符号链接需要 Windows 管理员权限。

import os
import platform

# Find the settings file in the same directory as this script
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
VS_SETTINGS_SRC_PATH = os.path.join(SCRIPT_DIR, 'settings.json')

# https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations
if platform.system() == 'Windows':
    VS_SETTINGS_DST_PATH = os.path.expandvars(r"%APPDATA%\Code\User\settings.json")
elif platform.system() == "Darwin":
    VS_SETTINGS_DST_PATH = os.path.expandvars(r"$HOME/Library/Application Support/Code/User/settings.json")
elif platform.system() == "Linux":
    raise NotImplementedError()
else:
    raise NotImplementedError()

# On Windows, there might be a symlink pointing to a different file
# Always remove symlinks
if os.path.islink(VS_SETTINGS_DST_PATH):
    os.remove(VS_SETTINGS_DST_PATH)

choice = input('symlink %r -> %r ? (y/n) ' % (VS_SETTINGS_SRC_PATH, VS_SETTINGS_DST_PATH))
if choice == 'y':
    os.symlink(VS_SETTINGS_SRC_PATH, VS_SETTINGS_DST_PATH)
    print('Done')
else:
    print('aborted')

User Settings用户设置

There is currently no automatic synchronization for user settings available in Visual Studio Code.目前没有针对 Visual Studio Code 中可用的用户设置的自动同步。 On Windows the user settings are located in %APPDATA%\\Code\\User\\settings.json .在 Windows 上,用户设置位于%APPDATA%\\Code\\User\\settings.json You could save a copy of that file on OneDrive or Dropbox and move it on all your machines to the user settings folder.您可以在 OneDrive 或 Dropbox 上保存该文件的副本,然后将其在所有计算机上移动到用户设置文件夹。 But this still includes manual steps on each machine every time you change the configuration.但这仍然包括每次更改配置时在每台机器上的手动步骤。

You can suggest an automatic synchronization of settings here: https://visualstudio.uservoice.com/forums/293070-visual-studio-code您可以在此处建议自动同步设置: https : //visualstudio.uservoice.com/forums/293070-visual-studio-code

Workspace Settings工作区设置

Add the .vscode folder of your workspace to the version control system (Git/SVN etc).将工作区的.vscode文件夹添加到版本控制系统(Git/SVN 等)。 When you checkout the code from the repository you will automatically get the VS Code workspace settings.当您从存储库签出代码时,您将自动获得 VS Code 工作区设置。

这最终是一个内置功能:请参阅Visual Studio Code 中的设置同步

使用工作区设置而不是用户设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM