Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to activate auto indentation in Powershell ISE in windows?

Tags:

powershell

I am using Powershell ISE to write script in windows 7. While writing scripts I have to maintain indentation manually. I didn't find a way to auto indent the script.

Is there any way to perform/enable auto indentation in Powershell ISE or do we need to install any plugin for it?

like image 807
Madhusudan Avatar asked Apr 11 '16 03:04

Madhusudan


People also ask

Is indentation required in PowerShell?

Use four spaces per indentation levelFor most programming languages and editors (including PowerShell ISE) the default is four spaces, and that's what we recommend. Different teams and projects may have different standards, and when contributing to a project, you should abide by the predominant style, of course.

How do I type in Windows PowerShell?

To enter text in the Script PaneMove the cursor to the Script Pane by clicking anywhere in the Script Pane, or by clicking Go to Script Pane in the View menu. Create a script. Syntax coloring and tab completion provide a richer editing experience in Windows PowerShell ISE.


2 Answers

Vanilla PowerShell ISE doesn't support auto indentation, There are lots of 3rd party ISEs that support it.

Closest you will get in Vanilla PowerShell is the ability to indent multiple lines at once. Put the caret where you want to indent Press Shift + Alt + Arrow Up or Down and it will create a line vertically across your rows of text. Press Tab and it will indent all those lines. This lets you indent whole code blocks and functions.

like image 59
Nick Avatar answered Oct 22 '22 04:10

Nick


Visual Studio Code is probably the best free editor (not only) for powershell scripts. Just open a .ps file with it and you will be suggested to install an appropriate powershell-extension. Then you have auto-format, instellisense, version-control-integration and you can run and debug the scripts from within the editor.

like image 3
Géza Avatar answered Oct 22 '22 05:10

Géza