Is there any way to sync my Visual Studio Code set

2019-01-30 03:59发布

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.

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.

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: there's a feature request for this here. If you want this feature, please give it a thumbs up.

8条回答
Deceive 欺骗
2楼-- · 2019-01-30 04:05

You can make a hard link from the directory containing user settings to your sync directory of applications such as Dropbox or OneDrive.

For example, on windows, the user settings are located in %APPDATA%\Code\User, so you could type:

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

on your computers with Visual Studio Code to achieve the synchronization.

Then, on another computer, you may delete the %APPDATA%\Code\User folder, and type:

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

to retrieve the synchronized settings.

查看更多
▲ chillily
3楼-- · 2019-01-30 04:06

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. Creating symlinks requires admin privileges on 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')
查看更多
相关推荐>>
4楼-- · 2019-01-30 04:06

Use workspace-settings instead of user-settings.

查看更多
SAY GOODBYE
5楼-- · 2019-01-30 04:16

User Settings

There is currently no automatic synchronization for user settings available in Visual Studio Code. On Windows the user settings are located in %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. 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

Workspace Settings

Add the .vscode folder of your workspace to the version control system (Git/SVN etc). When you checkout the code from the repository you will automatically get the VS Code workspace settings.

查看更多
乱世女痞
6楼-- · 2019-01-30 04:21

Another way of doing it would be to soft link your files, which can also be stored in a repository on GitHub. For example, on Mac OS let's say you have a directory called ~/dev/dotfiles/vscode. Let's say there are two files in there called settings.json and keybindings.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

查看更多
在下西门庆
7楼-- · 2019-01-30 04:22

Aha, you can try my VSCode extension: Syncing.

Hoping you'll like it. :)


A Quick Guide

  1. Install Syncing:

  2. Get your own GitHub Personal Access Token:

    1. Login to your GitHub Settings page.

      login to settings page

    2. Select Personal access tokens tab and click Generate new token.

      generate new token

    3. Select gist and click Generate token.

      allow gist

    4. Copy and backup your token.

      copy and backup token

  3. Sync your settings:

    Syncing will ask for necessary information for the first time and save for later use.

    1. Upload:

      1. Type upload in VSCode Command Palette.

      2. Enter your GitHub Personal Access Token.

      3. Enter your Gist ID (or leave it blank to create automatically).

      4. Done!

      5. After uploading, you can find your settings and the corresponding Gist ID in your GitHub Gist.

        settings and gist

    2. Download:

      1. Type download in VSCode Command Palette.

      2. Enter your GitHub Personal Access Token (or leave it blank if you want to download from a public Gist)

      3. Enter your Gist ID (or a public Gist ID).

      4. Done!

查看更多
登录 后发表回答