Every few years I find myself transitioning from one text editor to another. Starting with NotePad++ I moved to Sublime Text, then Atom, and more recently to Visual Studio Code. Just for clarification, I run a Mac but one reason I’ve liked VS Code so much is because of how it works across platforms, especially Windows. If you’re really just interested in the setup, scroll down a little. Before I get to that though, I want to highlight a few reasons why VS Code has become one of my favorites.
-
Cross Platform - VS Code works more or less equally across Windows, Mac, and Linux giving a consist interface and experience despite your operating system. Plus, it being a Microsoft product makes it great for Windows users.
-
Git Integration - Git is hard. Especially when you are new and especially when you don’t feel at home in a shell. Git is a HUGE part of an Ansible code workflow or really any modern “devops” practices. The graphical git controls help make this easier for newcomers.
-
Integrated Shell - VS Code offers an integrated shell that can be opened in the interface reducing the number of windows and switching you need to do. You can customize what shell is actually used too (eg. open a bash shell on Windows).
Visual Studio Code Install/Setup
Here are the instructions I recommend to get VS Code installed and configured on a Windows system.
-
Download and Install VS Code from code.visualstudio.com
-
Run the installer
-
Download and Install Git for Windows from gitforwindows.org
Visual Studio Code is now installed. Next we will install Git and configure the integration with VS Code.
- Run the Installer for Git
- Accept the license
- Select install Destination and WRITE THIS DOWN. We will need it later
- Select Components. These can be left as defaults
- Menu Options. These can be left as defaults
- Default Editor. Change to Visual Studio Code
- Adjust your PATH. Leave as default
- SSL Library. Leave as default
- Checkout Style. Leave as default
- Terminal Style. Leave as default
- Extra Option. Leave as default
-
Open a file explorer Windows and navigate to where Git was installed (
C:\Program Files\Git
by default). Look for a directory calledbin
. Insidebin
you should findbash.exe
. Make a note of the full path. By default, this should beC:\Program Files\Git\bin\bash.exe
-
Open VS Code, navigate to
File > Preferences > Settings
. In the Settings tab, search forintegrated shell
. The setting we are looking for should look like “Terminal > Integrated > Shell:Windows” and have a path topowershell.exe
. Replace the path topowershell.exe
with the path tobash.exe
from the previous step. Make sure to do aFile > Save
before closing. - Close and reopen VS Code. Select
View > Terminal
and the bottom section of the interface should open a terminal to a bash prompt.
At this point, VS Code is installed and configured to use a bash shell. If you’d like to use the git integration, follow the next steps for creating your ssh keys.
-
In the terminal, type
ssh-keygen
. You will be given several prompts. Proceed by pressing enter for each of them to accept defaults. -
Now that you have a key pair created,
cat
your public key with the commandcat ~/.ssh/id_rsa.pub
. Copy the blob starting withssh-rsa
. -
Finally, add the public key that you copied to your Git server.
On Github you can find this by clicking your avatar in the top right corner, selecting
Settings
, then selectingSSH and GPG Keys
from the left side.In BitBucket, click your avatar in the bottom left corner, choose
Settings
, then look for theSSH Keys
section under Security.NOTE: if you are new to using SSH keys, it is ok to share your public key (
id_rsa.pub
) with others but DO NOT share your private key (id_rsa
). Sharing your private key is the equivalent of giving away your password.