In PowerShell at the command line, how do I enter a tab indentation for multiple line commands?
Obviously, [tab]
or [shift] + [tab]
does not work, otherwise I would not ask this question.
In PowerShell at the command line, how do I enter a tab indentation for multiple line commands?
Obviously, [tab]
or [shift] + [tab]
does not work, otherwise I would not ask this question.
Using PSReadline (built-in to PS 5.1 or available via Install-Module
) you can make a custom key handler:
Set-PSReadlineKeyHandler -Chord 'ctrl+tab' -ScriptBlock {
$text = ''
$cursor = 0
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$text, [ref]$cursor)
$lastNewLine = [math]::max(0, $text.LastIndexOf("`n", $cursor - 1))
[Microsoft.PowerShell.PSConsoleReadLine]::Replace([math]::min($cursor, $lastNewLine + 1), 0, " ")
}
Then Ctrl+Tab
will indent the line which the cursor is on, no matter where in the line the cursor is.
Extending this to multiple lines, when you can't really select multiple lines in the console, is left as an exercise for the reader.