Set vscode as the default editor for text files on mac

Published on September 15, 2021

If you use VSCode you might want to set it the default editor for all text and code files on your mac.

I’ll first describe how to configure vs code as the editor when you open a file in Finder. The second section will describe how to set code as the editor in shell and git.

Setting vscode as the default editor for text files in Mac Finder

  1. First you should find the name of your vscode editor. Use this shell command.
osascript -e 'id of app "Visual Studio Code"'

This will probably return Use the command output on your Mac in the script below if it’s different.

  1. You will use duti to change the default handler for a file type on mac. Install duti with brew or your package manager.
brew install duti
  1. To set all text files and code files to vscode instead of xcode use this set of shell commands.
duti -s public.json all
duti -s public.plain-text all
duti -s public.python-script all
duti -s all
duti -s public.source-code all
duti -s public.text all
duti -s public.unix-executable all
# this works for files without a filename extension
duti -s all

duti -s .c all
duti -s .cpp all
duti -s .cs all
duti -s .css all
duti -s .go all
duti -s .java all
duti -s .js all
duti -s .sass all
duti -s .scss all
duti -s .less all
duti -s .vue all
duti -s .cfg all
duti -s .json all
duti -s .jsx all
duti -s .log all
duti -s .lua all
duti -s .md all
duti -s .php all
duti -s .pl all
duti -s .py all
duti -s .rb all
duti -s .ts all
duti -s .tsx all
duti -s .txt all
duti -s .conf all
duti -s .yaml all
duti -s .yml all
duti -s .toml all

Setting vs code as the default editor in shell and git

  1. The first step is to install code to your command line. From the Visual studio code documentation: “Launch VS Code. Open the Command Palette (Cmd+Shift+P) and type ‘shell command’ to find the Shell Command: Install ‘code’ command in PATH command.”

  2. Set these env vars in the rc file for your shell. This might be ~/bash-profile or ~/zshrc for example.

export EDITOR="code"
export VISUAL="code"
  1. Now set the git config to use vscode
git config --global core.editor "code -n --wait"


That’s it! You should be able to open any of those kinds of files with VSCode on your Mac now.

Update 29 Jan 2022 - I added this and more to comprehensive instructions for configuring a modern developer shell and MAcOS in another article here.

You can find my full set developer environment setup scripts with this and a lot more built in for Mac and Windows WSL -

Darragh ORiordan

Hi! I'm Darragh ORiordan.

I live and work in Sydney, Australia building and supporting happy teams that create high quality software for the web.

I also make tools for busy developers! Do you have a new M1 Mac to setup? Have you ever spent a week getting your dev environment just right?

My Universal DevShell tooling will save you 30+ hours of configuring your Windows or Mac dev environment with all the best, modern shell and dev tools.

Get DevShell here: ✨

Read more articles like this one...

List of article summaries


Start tracking DORA metrics for your team in just 15 minutes with Apache Dev Lake

DORA (DevOps Research and Assessment) metrics are an excellent way for engineering organisations to measure and improve their performance.

Up until now, monitoring the DORA metrics across Github, Jira, Azure Devops etc required custom tooling or a tedious manual process.

With Apache Dev Lake you can get beautiful reporting for DORA metrics on your local machine in as little as 15 minutes (honestly!).

From Google Sheets to Grafana
From Google Sheets to Grafana


How to use SSH with Git and ssh-agent on Windows

I needed to run git natively in windows (no wsl) for a recent project. I use ssh certificates with passphrases to authenticate with my git provider.

Ssh requires the certificate passphrase every time you use a connection. It’s annoying typing this passphrase in to terminal when using a git command.


How to fix custom type definitions not being type checked

If you have a custom types file (e.g. myTypes.d.ts) but you get no errors from the type checker and compiler in typescript even though you know there are issues in the file you might have skipLibCheck turned on.


Consistent modern shell tooling on MacOS and Windows WSL for developers

I regularly code on both MacOS and Windows machines and I was always annoyed how different the default experiences are on each. I need to use the same tools and the same experience on both.

Windows “WSL” (Windows Subsystem for Linux) is a great tool for this you can use on Windows 10 and newer. The latest version lets you run a full Ubuntu instance that integrates seamlessly with the underlying windows instance.

By using WSL2 you can have a (mostly) identical developer experience jumping between MacOS and Windows.

Better tooling for Developers

Many of the terminal tools that come with unix environments are functionally similar to how they were 20 years ago. But other developer tooling has advanced quite a bit since then.

You can replace tools like ls or cat with modern equivalents that support full colour, unicode icons, git state and more. Terminal prompts can be made git aware and use colour to indicate state so you don’t have to query git so often.

Keeping developer experience consistent across machines

Keeping any shell changes you make on one machine up to date on all the machines you code on is a nightmare without the right tooling.

This article also explains all the tools I use and how I keep the same terminal setup consistent on MacOS and Windows!

Let’s go!