PowerShell ISE - Is there a keyboard shortcut for commenting out lines or multiple lines

In PowerShell ISE I would like to comment out a line or multiple lines at once with a keyboard shortcut like how Sublime Text does this.

Is this possible to add or remove the # shown in the example below via a keyboard shortcut?

[console]::beep(350,400) < toggle betweeen these > #[console]::beep(350,400)

4 Answers

Not elegant but functional...

To Comment

"Block Select" at the start of all the lines by:

  • AltMouse-Left-Click-Dragor
  • AltShift while

... then ...

  • Shift3

To UnComment

"Block Select" all the # characters at start of all the lines by:

  • AltMouse-Left-Click-Dragor
  • AltShift while

... then ...

  • Delete
4

Old, but I just found this question and found this solution.

  • Select all the lines you want to comment
  • Ctrl-H to Replace in Script
  • Type ^ in 'Find what'
  • Type # in 'Replace with'
  • Check the Regular Expression check box
  • Replace All

Then in reverse use # in 'Find what' and nothing in 'Replace with'

1

Here are some ways to do that:

Here for multiple lines

Here for single and multiple lines (my choice)

And a detailed one

New solution using ISESteroids

This is a much better solution but it involves installing a plugin for the ISE.

  1. Paste this in the editor:Install-Module -Name "ISESteroids" -Scope CurrentUser -Repository PSGallery -Force

  2. Paste this to run it.Start-Steroids

  3. Then select the text and use the keyboard shortcut Ctrl+Shift+B

Now you have this functionality inside the editor.

To auto load ISESteroids

  1. To have ISESteroids load every time you start PowerShell ISE, click on the icon shown
  1. Paste this: Start-Steroids
  2. Save this file and closse.
  3. Next time you open PowerShell ISE, this plugin will load.

Older defunct answer

This AFAIK cannot be done in the native editor but it can with:

And by installing an extension called PowerShell by using the Ctrl + Shift + X and searching for PowerShell and installing.

This will allow debugging and syntax highlighting and also has the keyboard shortcuts for blocking out comments Like so:

  • Ctrl + / for toggling a line comment

  • Ctrl + Shift + A for to toggling block comments.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like