How to type a tab (indent) in comments in PowerShell ISE?
powershell, powershell-ise
Solution
To answer the main question, you can enter Alt+09 (using numeric keypad) to enter `<Tab>`.
For the behavior described, I see this as expected behavior. You can get history completion by typing `#` and part of a previous command then pressing Tab repeatedly will cycle backwards through matching history. Typing `#` alone will match all history starting with the last command.
Does this mean no-one uses tabs within comments in PowerShell scripts?
Anecdotal, but I've never used tabs in a single line comment, but I do often use tabs within multiline comments which are bracketed by `<#` and `#>`. E.g.
<#
Functions
Get-Foo
Get-Bar
Variables
$Foo
$Bar
#>
Function Get-Foo { ...
With multiline comments, the auto-completion will not be an issue.
, or that no-one uses comments in PowerShell scripts?
I don't know why this would be implied by the behavior; I always use a single space to start a line comment.
I find this helpful when developing a script as I often try expressions in the command pane if I'm unsure of the behavior, then add the expression to the script if it works.
So, my workflow would be:
- Ctrl-D to go to the Command Pane
- Type a command
- If the command did what I wanted, Ctrl-I to go to the Script Pane
- Type `#<Tab>`, and the line is added to the script.
Problem
This is weird. I know tab is for command completion in the PowerShell ISE and fine so. But, it also messes up the editing pane. Do this: File > New (`Untitled1.ps1` opens) Press tab (all fine, you get an indent) type enter, `#` (comment) and press tab after it expected: one would get indentation after the hash actual: one gets the hash replaced by `$PSVersionTable` or whatever the command prompt has in its history! (tab and Shift-tab circle through those) Does this mean no-one uses tabs within comments in PowerShell scripts, or that no-one uses comments in PowerShell scripts? Can I turn off this behavior anywhere? Also, the behavior seems to be inconsistent. If I e.g. type `##`, sometimes tab does not do the completion (it does not enter a tab either). Can others reproduce this? System: Windows 8.1 Pro PowerShell ISE