{"id":80965,"date":"2016-12-07T00:01:21","date_gmt":"2016-12-07T08:01:21","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=80965"},"modified":"2019-02-18T09:10:19","modified_gmt":"2019-02-18T16:10:19","slug":"make-visual-studio-code-more-like-the-integrated-scripting-environment","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/make-visual-studio-code-more-like-the-integrated-scripting-environment\/","title":{"rendered":"Make Visual Studio Code more like the integrated scripting environment"},"content":{"rendered":"<p><strong>Summary:<\/strong> Learn some handy tips to make Visual Studio Code work more like the ISE.<\/p>\n<p>I was very intrigued with the release of Visual Studio Code last year. An editor that is light-weight and integrated with Git is something worth considering. Well, any new tool that could be added to the tool box is worth considering. In the past, I used the integrated scripting environment (ISE) as my tool of choice to develop and edit PowerShell scripts but I\u2019m always looking for ways and tools to improve my PowerShell skills.<\/p>\n<p>There is a learning curve to Visual Studio Code. The ISE is very intuitive. I have never had much trouble figuring out how to use the ISE. Visual Studio Code is totally different. For one, after you install Visual Studio Code, you must install the PowerShell extension. Thankfully, MVP Keith Hill and the PowerShell Team have been extremely helpful by writing blogs on how to accomplish this.<\/p>\n<p><a target=\"_blank\" href=\"https:\/\/rkeithhill.wordpress.com\/2015\/12\/26\/getting-started-with-visual-studio-code-for-use-with-powershell\/\">Keith Hill \u2013 Getting Started with Visual Studio Code for Use with PowerShell<\/a><\/p>\n<p><a target=\"_blank\" href=\"https:\/\/blogs.msdn.microsoft.com\/powershell\/2015\/11\/16\/announcing-powershell-language-support-for-visual-studio-code-and-more\/\">PowerShell Team \u2013 Announcing PowerShell language support for Visual Studio Code and more!<\/a><\/p>\n<p>The two things, or pet peeves, of mine with Visual Studio Code is that the PowerShell terminal is not at the bottom of the editor like the ISE. I could not run a single line of code by pressing F8 like I can in the ISE. After I run that line of code, I want to be able to manipulate it in the terminal also. By default, Visual Studio Code will run code when editing PowerShell by pressing F8, but the output of that code goes to the <strong>OUTPUT<\/strong> window and not the terminal. The output cannot be manipulated from the <strong>OUTPUT<\/strong> window. For example, in the following screenshot, I run the first line of code by pressing F8. However, there is no prompt, so I can\u2019t manipulate the results.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSG-120716.png\"><img decoding=\"async\" width=\"537\" height=\"250\" class=\"alignnone size-full wp-image-80975\" alt=\"The OUTPUT window\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSG-120716.png\" \/><\/a><\/p>\n<p>Here is a screenshot of the terminal. You can see the prompt. This is what I want to see right after executing a line of code in the editor. Basically, I want it to act like the ISE.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSG-120716.png\"><img decoding=\"async\" width=\"624\" height=\"163\" class=\"alignnone size-full wp-image-80985\" alt=\"Screenshot of the terminal\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSG-120716.png\" \/><\/a><\/p>\n<p>Lucky for me, my first pet peeve can be resolved by following the instructions in the <a target=\"_blank\" href=\"https:\/\/code.visualstudio.com\/docs\/editor\/integrated-terminal\">Visual Studio Code Integrated Terminal Doc<\/a> page. However, my second pet peeve (run a line of code by pressing F8) and make it behave like the ISE would take some digging.<\/p>\n<p>My good friend, colleague, Honorary Scripting Guy <a target=\"_blank\" href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/tag\/brian-wilhite\/\">Brian Wilhite<\/a>, and I found some free time to figure this out. We noticed when we looked through the <strong>File<\/strong> &gt; <strong>Preferences<\/strong> menu in Visual Studio Code that there is a <strong>Keyboard Shortcuts<\/strong> options. When you select <strong>Keyboard Shortcuts<\/strong>, two JSON files open. This is like the process for making PowerShell an integrated terminal.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3-HSG-120716.png\"><img decoding=\"async\" width=\"396\" height=\"474\" class=\"alignnone size-full wp-image-80995\" alt=\"The Keyboard Shortcuts menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3-HSG-120716.png\" \/><\/a><\/p>\n<p>When you do a find for F8 by doing a <strong>Ctrl+F<\/strong>, I see two options for F8.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4-HSG-120716.png\"><img decoding=\"async\" width=\"628\" height=\"41\" class=\"alignnone size-full wp-image-80956\" alt=\"The first option for F8\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4-HSG-120716.png\" \/><\/a><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5-HSG-120716.png\"><img decoding=\"async\" width=\"645\" height=\"35\" class=\"alignnone size-full wp-image-81005\" alt=\"The second option for F8\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5-HSG-120716.png\" \/><\/a><\/p>\n<p>The second screenshots tell Visual Studio Code to run the selected text when the editor has focus and has a PowerShell script open. Now, we just need the output to go to the terminal. I stumbled on my solution by pure luck or as Brian likes to say, \u201cmore of an educated guess\u201d. There are numerous examples in the Default Keyboard Shortcuts file that are commented out. To quickly scan through the commented examples, I did find on <em>run<\/em> and reviewed every example until I came across this one:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6-HSG-120716.png\"><img decoding=\"async\" width=\"359\" height=\"24\" class=\"alignnone size-full wp-image-81015\" alt=\"Example of one result for search for &quot;run&quot;\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6-HSG-120716.png\" \/><\/a><\/p>\n<p>I\u2019m going to be honest here. Looking at this example, I am not 100% sure that it will do what I want. It has the words <em>terminal<\/em> and <em>runSelectedText<\/em>. My hopes and wishes were very strong at this point, so what does it hurt to try? I added the following to my keybindings.json:<\/p>\n<p style=\"padding-left: 30px\"><code>\/\/ Place your key bindings in this file to overwrite the defaults<\/code><\/p>\n<p style=\"padding-left: 30px\"><code>[<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>{<\/code><\/p>\n<p style=\"padding-left: 90px\"><code>\"key\": \"f8\",\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"command\":\"workbench.action.terminal.runSelectedText\",<\/code><\/p>\n<p style=\"padding-left: 120px\"><code>\"when\": \"editorTextFocus &amp;&amp; editorLangId == 'powershell'\"<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>}<\/code><\/p>\n<p style=\"padding-left: 30px\"><code>]<\/code><\/p>\n<p>I then highlighted a line of code, pressed F8, and tried to manipulate the output in the terminal. After I saw the results, I smiled as I just brought Visual Studio Code closer to the ISE.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7-HSG-120716.png\"><img decoding=\"async\" width=\"554\" height=\"324\" class=\"alignnone size-full wp-image-81025\" alt=\"Result after modification of keybindings.json file\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7-HSG-120716.png\" \/><\/a><\/p>\n<p>There is without a doubt a learning curve to Visual Studio Code, but the more I use it, the more I like it. As a note, I wanted to write this blog as a story as I do not claim to be an expert on Visual Studio Code. I just wanted to share my story. If you have any Visual Studio Code tips and tricks, I would love to hear about them in the comments.<\/p>\n<p><strong>Jason Walker<\/strong>\nSenior Consultant\nMicrosoft Public Sector Services<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn some handy tips to make Visual Studio Code work more like the ISE. I was very intrigued with the release of Visual Studio Code last year. An editor that is light-weight and integrated with Git is something worth considering. Well, any new tool that could be added to the tool box is worth [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[568,641],"tags":[499,338,377,701],"class_list":["post-80965","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-windows-powershell","tag-guestblogger","tag-jason-walker","tag-powershell","tag-visual-studio-code"],"acf":[],"blog_post_summary":"<p>Summary: Learn some handy tips to make Visual Studio Code work more like the ISE. I was very intrigued with the release of Visual Studio Code last year. An editor that is light-weight and integrated with Git is something worth considering. Well, any new tool that could be added to the tool box is worth [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/80965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=80965"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/80965\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=80965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=80965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=80965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}