A Little History on PowerShell Editors
Since 2009, PowerShell users have been rewarded with an improvement over Notepad, for authoring PowerShell scripts and modules. That tool is called the PowerShell Integrated Scripting Editor (ISE), which was originally included out-of-box with Windows 7 and PowerShell version 2.0. Over the years, PowerShell developers have used tools like Quest PowerGUI and Visual Studio with the PowerShell Tools Extension to write, test, and debug their PowerShell code. In fact, not all that long ago, I wrote about moving from PowerGUI over to Visual Studio for your PowerShell development work. Since then, the momentum in the software field has gotten more and more agile, requiring developers to invest more and more time learning, and less time focusing on their business logic.
So Where Are We Now?
Over the past months, we’ve seen a rapid rise in a new, cross-platform editor called Visual Studio Code. Cross-platform software development is the real deal these days. No longer are we restricted to platform-specific software development tools; you choose the platform, you choose the development tools, and you start writing code.
Visual Studio Code, frequently abbreviated as VSCode, is an open source editor that’s built on the Electron user interface API from GitHub. One of the great things about VSCode is that it’s extensible, just like the full Visual Studio product is also extensible. You might be wondering: why should I use VSCode instead of Visual Studio? Well, to be honest, there are tons of things that I prefer about VSCode over Visual Studio, and I’ll outline these below.
Why You Should Use VSCode for PowerShell
The most important part of your software project is your code. Thankfully, VSCode gives you full control over your code with functions such as text encoding, customized indentation (2 spaces, please!), global search / replace functionality, revision control integration, and much more. One of the huge limitations of PowerShell ISE is that you can’t customize your indentation. I personally like to set my indentation to two spaces, instead of a 4-spaced tab, and VSCode gives me the ability to control that for my entire user account, or for specific workspaces (projects).
When writing code in any language, one of the most useful capabilities I enjoy using is Intellisense, or predictive typing. Intellisense, sometimes called auto-completion or tab-completion, reduces the amount of typing you have to do as a developer, reduces the memorization of API calls, parameter names, parameter types, and also reduces the need to context switch over to your web browser to look up API documentation. Documentation is super helpful as a developer, but if your development tooling can integrate documentation with code, you can be dramatically more efficient in authoring applications. Thankfully, the PowerShell Intellisense is pretty strong, albeit not perfect, in VSCode. Performance could be better, and there are bugs in the Intellisense, but all things considered, I’d much rather leverage the massive benefits of VSCode vs. being stuck in the old 2009 days of PowerShell ISE.
One of the most important benefits of Visual Studio Code is its performance. The full version of Visual Studio is incredibly powerful, reliable, and extensible, but that often came with a huge performance hit. This rang especially true if you had lots of extensions installed, or tried to load a very large project with lots of files. Of course, an adequately powerful developer workstation had no problem running Visual Studio, and many people use it today quite happily.
On the other hand, VSCode opens much more quickly, is much “snappier” when clicking on various UI elements and overall just feels very fast. Switching between major editor functions, such as the project explorer, search, revision control, debugging, and extensions, is very fast, and accessing components like the Command Palette (see below) is incredibly responsive, especially when hitting your favorite keyboard shortcut to invoke it. Overall, Visual Studio Code gets an “A” from me on performance.
In any software development environment, you’ll need the ability to extend and adapt it to your needs. It doesn’t really matter what language you’re authoring software in, you’ll still need build tools, debugging, rich text editing tools, revision control tools, and more. Visual Studio Code comes with built-in support for Git, but you can also download extensions that enable you to interact with Mercurial, if that’s your thing. There’s extensions that enable syntax highlighting, debugging, Intellisense, code snippets, custom file icons, and much more, for pretty much any language you can think of. There’s first-class support for Python, Ruby, C#, Java, PowerShell, and much more!
One of the cool things about VSCode is how it manages projects. In short, you can open any folder on your filesystem as a project. This means you can scope your editor to a specific application component that you’re focused on, or you can get a larger perspective of your entire project by opening a folder a few levels up in your folder hierarchy. Of course, you can open individual files too, but being able to open an entire folder as a project is a huge benefit that VSCode has over the PowerShell ISE. In the PowerShell ISE, it was easy to get lost in your project if you weren’t paying close attention to which file you were editing. With VSCode, that problem disappears for the most part!
While it may sound trivial, the ability to create and apply custom themes to Visual Studio Code is really awesome. It’s nice to have a change of pace throughout your day writing code, and switching your theme takes a matter of a few seconds. You can also search for new themes on the Visual Studio Marketplace, and install them, all directly from VSCode. The theme that you use in your development environment depends a lot on your physical environment and your mood. Sometimes I like a deep, colorful theme, sometimes I like muted, soft colors, and sometimes I like a nice high-contrast theme. The great thing about VSCode is that I can get all of the above with a few simple key presses.
Want to install a theme, or change your theme? Simply launch the Command Palette and search for “theme” or “extension.” In the Visual Studio Marketplace, themes are considered extensions.
PowerShell ISE offers limited support for themes, and I actually wrote a PowerShell module to import themes in ISE. However, previewing and switching themes is nowhere near as easy as VSCode!
I’ll be honest, the Command Palette is a game-changer in software user interfaces. After having the Command Palette available in Visual Studio Code, I started wishing that every piece of software out there offered a similar user interface. The Command Palette enables you to search for the function that you’re looking for, rather than resorting to manually using your mouse to look through all of the menus at the top of the screen. Want to do a “git push?” All you need to do is search for “push” and it will come up. Want to perform some PowerShell-specific operation? Pull up the Command Palette, search for PowerShell, and you’ll see all of your commands neatly filtered in the Command Palette.
Another massive benefit of the Command Palette is that you can not only search for development environment commands, but you can naturally learn keyboard shortcuts along the way. Don’t know what the keyboard shortcut is for a particular editor command? That doesn’t matter, because the Command Palette will show you the keyboard shortcut when you search for a command. That way, the next time you need to call that same command again, all you have to do is use the keyboard shortcut, and you’ll be on your way to deep productivity!
While the Command Palette can easily be invoked with CMD + SHIFT + P, or just hitting the F1 key, another really cool feature of the Command Palette is the keyboard shortcut to switch between files in your workspace (project). All you do is hit CMD + P, type a small, unique part of the file you want to edit, and hit ENTER. BOOM! Just like that, you’ve opened up the editor to your desired file, and you didn’t even have to touch the mouse!
Conversely, the PowerShell ISE lacks any ability to switch to specific files using your keyboard, much less using search. Sure, you can use CTRL + TAB and CTRL + SHIFT + TAB to go forward and back between open tabs, but if you have a large number of files open, this can be a huge pain to navigate.
The user interface in Visual Studio Code scales very well, which is especially useful on high-DPI displays. When you scale up the user interface, text and icons scale proportionally together. My guess is that most of this is thanks to the Electron API, but then again, I’m not familiar with the code base of VSCode that much. The UI is organized well, full screen mode works awesome for when you really need to get focused on writing your code, and you can even collapse the sidebar to maximize your screen real estate for your code editor area. I really love how “open” the VSCode editor experience feels, and it gives you, the user, a lot of control over how much or how little you want to see on-screen. This level of control helps VSCode have a “lightweight” feel to it.
On the flip side, the PowerShell ISE does not scale well on high-DPI displays. While ISE is built on the Windows Presentation Foundation (WPF) UI framework, which can scale well, it seems that the PowerShell ISE’s main menu and toolbars have been artificially restricted to a specific pixel size. Of course, I can’t validate that myself, but I’m just reporting my observations here. On a positive note, your code in PowerShell ISE does scale very well, with nice, crisp text; that’s one thing I’ve always loved about ISE.
Searching Your PowerShell Code
With the PowerShell ISE, it was easy to get lost in your code, and it could be very challenging to find references to functions, aliases, and other elements. In VSCode, you can search your entire folder project at once, using the powerful, built-in search feature, which is easily accessible using a keyboard shortcut! You can perform search and replace operations using regular expressions across your entire project, all at once. This feature isn’t one that I use particularly frequently, but knowing that it’s there is super useful if you’re in a bind, and need to find something across a huge number of files.
On the downside, the PowerShell extension for VSCode doesn’t support certain features like “Go to Definition” and “Find All References.” This is partially due to the dynamic nature of PowerShell and the fact that there isn’t a lot of analysis that can be done on your code before run-time, like with C# applications. However, the team that’s working on VSCode’s PowerShell extension is aware of these limitations, and hopefully we’ll see some improvement on it going forward.
While VSCode may not be everyone’s cup of tea, I certainly love the fact that I can write PowerShell code effectively on a non-Windows system. I haven’t given it a solid go on Linux yet, but I’m fairly confident that it will work almost just as well. Between the vast array of functionality, themes, extensions, and performance that it offers, I really feel like I’m in control of my software development experience when I’m using VSCode. If you aren’t using VSCode for PowerShell today, I’d encourage you to toss away your old editor, shift over to VSCode as your “daily driver,” and really invest yourself in learning about it and appreciating what it can offer you in terms of productivity.