{"id":1159,"date":"2014-06-17T00:01:00","date_gmt":"2014-06-17T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/06\/17\/a-better-powershell-command-line-edit\/"},"modified":"2014-06-17T00:01:00","modified_gmt":"2014-06-17T00:01:00","slug":"a-better-powershell-command-line-edit","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/a-better-powershell-command-line-edit\/","title":{"rendered":"A Better PowerShell Command-Line Edit"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, talks about using PSReadLine to improve command-line editing in Windows PowerShell.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today I thought I would try something a bit different. It is hard to show command-line editing with screenshots and tables of shortcuts. So today&rsquo;s post is basically two parts. The first part includes two tables that I built, which are basically reference material for the PSReadLine command-line enhancements.<\/p>\n<p>The second part is a short (less than two minutes) video. I recorded it to illustrate a simple command-line edit. My video is nothing like the way cool <a href=\"https:\/\/www.youtube.com\/watch?v=SpTS4O1nFyc&amp;feature=youtu.be\">Scripting Cmdlet Style<\/a> video, but it should prove to be somewhat helpful.<\/p>\n<h2>Cursor movement<\/h2>\n<p>One of the cool things about PSReadLine is that it adds a lot of ways to move around in the Windows PowerShell console. Learning a few keyboard shortcuts makes me a lot more productive, and it also saves my wrists and hands from a lot of extra typing and work. Here is a table that provides the cursor movement shortcuts. For the most part, they are straightforward, and they are inline with standard keyboard shortcuts used in other places.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p><b>Cursor Movement<\/b><\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p><b>Shortcut<\/b><\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p><b>Meaning<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>EndOfLine&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>&lt;End&gt;&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>Move the cursor to the end of the input.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>BeginningOfLine&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>&lt;Home&gt;&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>Move the cursor to the start of the input.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>ForwardChar&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>&lt;Right Arrow&gt;&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>Move the cursor one character to the right. This may move the cursor to the next line of multiline input.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>BackwardChar&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>&lt;Left Arrow&gt;&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>Move the cursor one character to the left. This may move the cursor to the previous line of multiline input.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>ForwardWord&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>unbound&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>Move the cursor forward to the end of the current word, or if between words, to the end of the next word. Word delimiter characters can be set with:<\/p>\n<p>Set-PSReadlineOption -WordDelimiters &lt;string of delimiter characters&gt;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>NextWord&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>&lt;Ctrl+Right Arrow&gt;&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>Move the cursor forward to the start of the next word. Word delimiter characters can be set with:<\/p>\n<p>Set-PSReadlineOption -WordDelimiters &lt;string of delimiter characters&gt;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>BackwardWord&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>&lt;Ctrl+Left Arrow&gt;&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>Move the cursor back to the start of the current word, or if between words, to the start of the previous word. Word delimiter characters can be set with:<\/p>\n<p>Set-PSReadlineOption -WordDelimiters &lt;string of delimiter characters&gt;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>ShellForwardWord&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>unbound&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>Like ForwardWord except word boundaries are defined by Windows PowerShell token boundaries.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>ShellNextWord&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>unbound&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>Like NextWord except word boundaries are defined by Windows PowerShell token boundaries.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>ShellBackwardWord&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>unbound&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>Like BackwardWord except word boundaries are defined by Windows PowerShell token boundaries.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>GotoBrace&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>&lt;Ctrl+}&gt;&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>Go to the matching parenthesis curly brace or square bracket.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"134\" valign=\"top\">\n<p>AddLine&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"125\" valign=\"top\">\n<p>&lt;Shift-Enter&gt;&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"379\" valign=\"top\">\n<p>The continuation prompt is displayed on the next line, and PSReadLine waits for keys to edit the current input. This is useful to enter multiline input as a single command even when a single line is complete input by itself.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<span style=\"font-size:1.5em\">Command-line editing<\/span><\/p>\n<p>One of the real strengths of PSReadLine is the enhanced command-line editing experience. Learning a few shortcuts will vastly improve the command-line editing experience. Most of the shortcuts make sense and are familiar to me.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p><b>Edit Function<\/b><\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p><b>Shortcut<\/b><\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p><b>Meaning<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>CancelLine<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>unbound<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Cancel all editing to the line and leave the line of input on the screen, but return from PSReadLine without executing the input.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>RevertLine<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;ESC&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Revert all of the input since the last input was accepted and executed. This is equivalent to doing Undo until there is nothing left to undo.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>BackwardDeleteChar<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Backspace&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Delete the character before the cursor.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>DeleteChar<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Delete&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Delete the character under the cursor.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>AcceptLine<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Enter&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Attempt to execute the current input. If the current input is incomplete (for example, there is a missing closing parenthesis bracket or quotation mark), the continuation prompt is displayed on the next line and PSReadLine waits for keys to edit the current input.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>AcceptAndGetNext<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>unbound<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Like AcceptLine but after the line completes, start editing the next line from history.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>BackwardDeleteLine<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Ctrl+Home&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Delete the text from the start of the input to the cursor.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>ForwardDeleteLine<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Ctrl+End&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Delete the text from the cursor to the end of the input.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelectBackwardChar<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Shift+Left Arrow&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Adjust the current selection to include the previous character.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelectForwardChar<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Shift+Right Arrow&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Adjust the current selection to include the next character.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelectBackwardWord<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Shift+Ctrl+Left Arrow&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Adjust the current selection to include the previous word.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelectForwardWord<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>unbound<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Adjust the current selection to include the next word using ForwardWord.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelectNextWord<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Shift+Ctrl+Right Arrow&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Adjust the current selection to include the next word using NextWord.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelectShellForwardWord<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>unbound<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Adjust the current selection to include the next word using ShellForwardWord.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelectShellNextWord<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>unbound<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Adjust the current selection to include the next word using ShellNextWord.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelectShellBackwardWord<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>unbound<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Adjust the current selection to include the previous word using ShellBackwardWord.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelectBackwardsLine<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Shift+Home&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Adjust the current selection to include from the cursor to the start of the line.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelectLine<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Shift+End&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Adjust the current selection to include from the cursor to the end of the line.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelectAll<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Ctrl+A&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Select the entire line. Moves the cursor to the end of the line.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>SelfInsert<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;a&gt; &lt;b&gt; &#8230;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Insert the key entered.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>Redo<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Ctrl+Y&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Redo an insertion or deletion that was undone by Undo.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"164\" valign=\"top\">\n<p>Undo<\/p>\n<\/td>\n<td width=\"152\" valign=\"top\">\n<p>&lt;Ctrl+Z&gt;<\/p>\n<\/td>\n<td width=\"323\" valign=\"top\">\n<p>Undo a previous insertion or deletion.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>I really love the command-line editing, and it makes things a whole lot faster. I just need to keep remembering the shortcuts, which is why I made the two tables above. I have them printed out on my desk so that I have easy reference. They are also in the About_PSReadLine Help topic that is part of the PSReadLine installation.<\/p>\n<p>Here is the video that illustrates using PSReadLine command-line editing to speed up Tab completion in Windows PowerShell:<\/p>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=rVvmdFBjN_c&amp;feature=youtu.be\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/PSReadLine_GetProcess_First_Frame.png\" border=\"0\" alt=\" \" \/><\/a><\/p>\n<p>That is all there is to using PSReadLine on the Windows PowerShell console command line. PSReadLine week will continue tomorrow when I will talk about more cool stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using PSReadLine to improve command-line editing in Windows PowerShell. Microsoft Scripting Guy, Ed Wilson, is here. Today I thought I would try something a bit different. It is hard to show command-line editing with screenshots and tables of shortcuts. So today&rsquo;s post is basically two parts. The [&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":[1],"tags":[516,3,4,45],"class_list":["post-1159","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-psreadline","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using PSReadLine to improve command-line editing in Windows PowerShell. Microsoft Scripting Guy, Ed Wilson, is here. Today I thought I would try something a bit different. It is hard to show command-line editing with screenshots and tables of shortcuts. So today&rsquo;s post is basically two parts. The [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1159","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=1159"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1159\/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=1159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}