

Make sure Find in Selection and Regular expressions are selected: Then Ctrl-H to get the Find and Replace dialog box. When clicking at the right of the text on line 40 and after pressing Shift-Alt and the up arrow several times, you’ll see the blue line:Īfter pressing # you’ll see the characters added to the code:Īs a note, you can use this trick anywhere on the line (so if you wanted to put a bunch of comments at the end of a number of lines you could use this trick to easily put in the # for you) and is obviously not specific to commenting, but that’s one of the most obvious usages. You can also do this using regular expressions. This is an example of the code to comment:

Once you’ve marked the lines you want to comment, simply type a # and it will appear at the start of each line. You will notice a thin line (blue on my screen) appear. It’s a keyboard shortcut that’s not comment specific but useful if you have a chunk of code you want to comment out, say for testing. Put the cursor at the start of the line and holding down Shift-Alt use the arrow keys to move it up or down. If you, like me, often use the PowerShell ISE to write scripts, there is one last useful trick I want to share, but can only describe and give some screenshots for, not actually provide a script for it.

That would work, but I wanted to give an example of how to escape the # qualifier.
