I’ve been working in Visual Studio pretty heavily in the last two weeks, but every once in a while I need to make quick edits to my .gitignore file, which isn’t in my project directory.
I usually open up a small text editor right from PowerShell and now that VS Code is out I thought ‘why not use that?’
Here’s how you can easily open files using code from PowerShell in three steps:
1.Find the path to VS Code
2. Edit your PowerShell profile
3. Open Files!
1. Find the VS Code Path
First thing we need to do is find where VS Code is in our directory.
If you have Code pinned to your start menu or on your desktop simply right click the icon and ‘select open file location’.
File explorer should now open to the location of the .exe.
Right click the Code.exe file and select ‘properties’.
If you selected a Shortcut Icon you should see a screen like this:
If you navigated to the actual location in directory of VS Code it should look like this:
Now right click and copy the path.
In my case: C:\Users\tireilly\AppData\Local\Code\app-0.1.0
2. Edit our PowerShell profile
To edit our profile we need to find the Microsoft.PowerShell_profile.ps1 file.
My file is located here:
I open the file in notepad to make my edits:
Now that we have our profile open we’ll create an alias for labeled code followed by the path to our .exe
eg: Set-Alias code ‘C:\Users\user\AppData\Local\Code\app-0.1.0\Code.exe
noticed how I added the Code.exe to the path so the program will launch!
Here’s a photo of my current PowerShell profile for reference:
Now we can save and close this file and open a new PowerShell window!
3. Edit some files!
Let’s edit our PowerShell profile with Code this time!
Something oddly satisfying about getting exactly what you want with words.
And there we go. The brand new Code editor at your fingertips whenever you need it!
Let me know if you have any comment or questions!