I have personal preferences for how I author code. Like anyone, I’m opinionated my coding experience. I prefer using ligatures, cursive fonts for comments, VSCode themes, and more.
The problem is that I am always switching between personal/client projects and recording tutorials on my YouTube channel. I don’t want to have to change my VSCode settings every time I switch between projects, so it’s mostly been an unhappy compromise where neither my personal coding environment nor my tutorial coding environment is ideal.
TL;DR
- Create a settings.json file for each non-default profile in a data/User directory.
- Open a directory with VSCode CLI (with the
--user-data-dir
flag pointing to your profile’s data directory).
Skip ahead to:
- How to create a VSCode profile
- How to use a VSCode profile
- Set up an alias for your profile
- Enable the VSCode CLI
How to create a VSCode profile
For each VSCode profile, you’ll create a unique VSCode settings.json config file.
1. Create a directory to hold your profiles.
I like to keep my profiles in a directory called vscode-profiles
in my home directory. You can put it wherever you want, but I recommend keeping it in a place that is easy to find and won’t get accidentally deleted.
Type the following from any open terminal.
mkdir ~/vscode-profiles
Change to that directory.
cd ~/vscode-profiles
Note: If you’re an ohmyzsh user, you can use take
in the place of mkdir
to create and cd into the newly-created directory at the same time.
2. Create a subdirectory for each profile.
For each profile, create a subdirectory with the name of the profile. I name mine screenrecording
but you can replace that title with your preference.
Type the following:
mkdir screenrecording
Then cd into that directory.
cd screenrecording
3. Create data and User subdirectories
When VSCode looks into your directory, it expects a data
subdirectory with its own User
subdirectory, so start by creating those two nested directories.
mkdir data/User`
Your folder structure should look like this (obviously with your own profile name in place of screenrecording
).
vscode-profiles
└── screenrecording
└── data
└── User
cd into the User
directory.
cd data/User
4. Create a settings.json file in the User subdirectory.
Make sure you’re in the User
subdirectory and then create a settings.json
file.
touch settings.json
5. Add your settings to the settings.json file.
Open your settings.json file in VSCode with the following command:
code settings.json
Note: If you’re on macOS and haven’t first enabled launching VSCode from the command line, the command above will not work. See below for instructions.
Add your desired settings to the file. Here’s an example I found from @avanslaars available here:
{
"editor.fontFamily": "JetBrains Mono, Dank Mono, Operator Mono",
"editor.tabSize": 2,
"editor.quickSuggestions": false,
"editor.suggestOnTriggerCharacters": false,
"editor.fontSize": 16,
"editor.fontLigatures": false,
"editor.multiCursorModifier": "ctrlCmd",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.tabCompletion": true,
"prettier.singleQuote": true,
"prettier.semi": false,
"prettier.trailingComma": "none",
"prettier.arrowParens": "avoid",
"workbench.colorTheme": "Night Owl",
"javascript.validate.enable": false,
"window.zoomLevel": 1.25,
"editor.cursorBlinking": "solid",
"editor.cursorStyle": "line",
"editor.minimap.renderCharacters": false,
"terminal.integrated.fontSize": 14,
"explorer.openEditors.visible": 0,
"workbench.settings.useSplitJSON": false,
"workbench.settings.editor": "json",
"workbench.sideBar.location": "right"
}
How to use a VSCode profile
When I open VSCode normally, it uses my default personal profile. To use a different profile, you can open VSCode from the command line with the --user-data-dir
flag pointing to the profile’s data directory.
For me that looks like this:
# code --user-data-dir PROFILE_DIRECTORY DIRECTORY_TO_OPEN>
code --user-data-dir ~/vscode-profiles/screenrecording/data
VSCode should open your desired directory with the settings from your profile’s settings.json file.
Note: If you’re on macOS and haven’t first enabled launching VSCode from the command line, the command above will not work. See below for instructions.
Set up an alias for your profile
If you’re going to be using a profile often, you can set up an alias to make it easier to open. I’ve set up an alias for my screenrecording
profile in my .zshrc file.
- Open your .zshrc file.
code ~/.zshrc
Note: I’m assuming you’re using zsh as your shell. If that’s not the case, your alias setup may look different than shown here.
- Add the following to the file.
# alias NAME_OF_ALIAS="code --user-data-dir PROFILE_DIRECTORY"
alias screenrecording='code --user-data-dir ~/vscode-profiles/screenrecording/data'
- Save the file and restart your terminal (or source the file with
source ~/.zshrc
).
Now, you can use your alias to open VSCode with your profile’s settings.
# NAME_OF_ALIAS DIRECTORY_TO_OPEN
screenrecording .
Enable the VSCode CLI
If you haven’t yet enabled launching VSCode from the command line:
- Open VSCode.
- Open the Command Palette (Cmd+Shift+P) and type
shell command
to find theShell Command: Install 'code' command in PATH command
.
Note: See this VSCode support article for more help.