PowerShell - PSReadLine 2.1, PSReadLine 2.2 + Predictive IntelliSens

Hello koalas

This post is about the module PSReadLine.

Table of Contents

Install PSReadLine

You can install the module from PowerShell Gallery by using this command:

Install-Module -Name PSReadLine

You can see all commands available for the module with this command:

Get-Command -Module PSReadLine

Result:

See all key bindings for PSReadLine

 
Type this command to see all key bindings for the PSReadLine module.
Get-PSReadLineKeyHandler

Result:

You should get this:

Basic editing functions

Key
Function
Description
Enter
AcceptLine
Accept the input or move to the next line if input is missing a closing token.
Shift+Enter
AddLine
Move the cursor to the next line without attempting to execute the input
Backspace
BackwardDeleteChar
Delete the character before the cursor
Ctrl+h
BackwardDeleteChar
Delete the character before the cursor
Ctrl+Home
BackwardDeleteLine
Delete text from the cursor to the start of the line
Ctrl+Backspace
BackwardKillWord
Move the text from the start of the current or previous word to the cursor to the kill ring
Ctrl+w
BackwardKillWord
Move the text from the start of the current or previous word to the cursor to the kill ring
Ctrl+C
Copy
Copy selected region to the system clipboard. If no region is selected, copy the whole line
Ctrl+c
CopyOrCancelLine
Either copy selected text to the clipboard, or if no text is selected, cancel editing the line with CancelLine.
Ctrl+x
Cut
Delete selected region placing deleted text in the system clipboard
Delete
DeleteChar
Delete the character under the cursor
Ctrl+End
ForwardDeleteLine
Delete text from the cursor to the end of the line
Ctrl+Enter
InsertLineAbove
Inserts a new empty line above the current line without attempting to execute the input
Shift+Ctrl+Enter
InsertLineBelow
Inserts a new empty line below the current line without attempting to execute the input
Alt+d
KillWord
Move the text from the cursor to the end of the current or next word to the kill ring
Ctrl+Delete
KillWord
Move the text from the cursor to the end of the current or next word to the kill ring
Ctrl+v
Paste
Paste text from the system clipboard
Shift+Insert
Paste
Paste text from the system clipboard
Ctrl+y
Redo
Redo an undo
Escape
RevertLine
Equivalent to undo all edits (clears the line except lines imported from history)
Ctrl+z
Undo
Undo a previous edit
Alt+.
YankLastArg
Copy the text of the last argument to the input

Cursor movement functions

Key
Function
Description
LeftArrow
BackwardChar
Move the cursor back one character
Ctrl+LeftArrow
BackwardWord
Move the cursor to the beginning of the current or previous word
Home
BeginningOfLine
Move the cursor to the beginning of the line
End
EndOfLine
Move the cursor to the end of the line
RightArrow
ForwardChar
Move the cursor forward one character
Ctrl+]
GotoBrace
Go to matching brace
Ctrl+RightArrow
NextWord
Move the cursor forward to the start of the next word

History functions

Key
Function
Description
Alt+F7
ClearHistory
Remove all items from the command line history (not PowerShell history)
Ctrl+s
ForwardSearchHistory
Search history forward interactively
F8
HistorySearchBackward
Search for the previous item in the history that starts with the current input - like PreviousHistory if the input is empty
Shift+F8
HistorySearchForward
Search for the next item in the history that starts with the current input - like NextHistory if the input is empty
DownArrow
NextHistory
Replace the input with the next item in the history
UpArrow
PreviousHistory
Replace the input with the previous item in the history
Ctrl+r
ReverseSearchHistory
Search history backwards interactively

Completion functions

Key
Function
Description
Ctrl+@
MenuComplete
Complete the input if there is a single completion, otherwise complete the input by selecting from a menu of possible
completions.
Ctrl+Spacebar
MenuComplete
Complete the input if there is a single completion, otherwise complete the input by selecting from a menu of possible
completions.
Tab
TabCompleteNext
Complete the input using the next completion
Shift+Tab
TabCompletePrevious
Complete the input using the previous completion

Miscellaneous functions

Key
Function
Description
Ctrl+l
ClearScreen
Clear the screen and redraw the current line at the top of the screen
Alt+0
DigitArgument
Start or accumulate a numeric argument to other functions
Alt+1
DigitArgument
Start or accumulate a numeric argument to other functions
Alt+2
DigitArgument
Start or accumulate a numeric argument to other functions
Alt+3
DigitArgument
Start or accumulate a numeric argument to other functions
Alt+4
DigitArgument
Start or accumulate a numeric argument to other functions
Alt+5
DigitArgument
Start or accumulate a numeric argument to other functions
Alt+6
DigitArgument
Start or accumulate a numeric argument to other functions
Alt+7
DigitArgument
Start or accumulate a numeric argument to other functions
Alt+8
DigitArgument
Start or accumulate a numeric argument to other functions
Alt+9
DigitArgument
Start or accumulate a numeric argument to other functions
Alt+-
DigitArgument
Start or accumulate a numeric argument to other functions
PageDown
ScrollDisplayDown
Scroll the display down one screen
Ctrl+PageDown
ScrollDisplayDownLine
Scroll the display down one line
PageUp
ScrollDisplayUp
Scroll the display up one screen
Ctrl+PageUp
ScrollDisplayUpLine
Scroll the display up one line
Ctrl+Alt+?
ShowKeyBindings
Show all key bindings
Alt+?
WhatIsKey
Show the key binding for the next chord entered

Selection functions

Key
Function
Description
Ctrl+a
SelectAll
Select the entire line. Moves the cursor to the end of the line
Shift+LeftArrow
SelectBackwardChar
Adjust the current selection to include the previous character
Shift+Home
SelectBackwardsLine
Adjust the current selection to include from the cursor to the start of the line
Shift+Ctrl+LeftArrow
SelectBackwardWord
Adjust the current selection to include the previous word
Shift+RightArrow
SelectForwardChar
Adjust the current selection to include the next character
Shift+End
SelectLine
Adjust the current selection to include from the cursor to the end of the line
Shift+Ctrl+RightArrow
SelectNextWord
Adjust the current selection to include the next word

Search functions

Key
Function
Description
F3
CharacterSearch
Read a character and move the cursor to the next occurence of that character
Shift+F3
CharacterSearchBackward
Read a character and move the cursor to the previous occurence of that character

Enable Predictive IntelliSense History

Important: you must have PSReadLine 2.1 or higher to be able to enable this functionality.

Check what is the status of the predictive option with this command:

Get-PSReadLineOption | Select-Object -Property PredictionSource

Result:

none

Enable the predictive option with this command:

Set-PSReadLineOption -PredictionSource History

You should see prediction in grey when you start typing:

Enable Plugin Prediction (PSReadLine 2.2.0 or higher)

Important: you must install PSReadLine 2.2.0 or higher to access this functionality.

Check the last version of PSReadLine on PowerShell Gallery with this command:

Find-Module -Name PSReadLine -AllVersions -AllowPrerelease

Result (April 10th 2021):

Install the last version available:

Update-Module -Name PSReadLine -AllowPrerelease

Check you get the version 2.2.0 or higher of PSReadLine with the command:

Get-Module -Name PSReadLine

Result:

Now you should be able to set your module to get access to the ListView.

Here are the commands to use:

Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView

Result:

Advice: you should add the 2 previous commands in your profile.

You can edit your profile by using this command:

notepad $profile

or

code $profile

An example of the lines I added to my profile to load the new predictive system of PSReadLine:

# PSReadLine Predictive System
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView

Result:

Switch Predictive View between InlineView and ListView

if you want to switch view between the InlineView and the ListView you can simply press: F2

Sources used

NameLink
Transforming PowerShell experience with PSReadLineLink
Announcing PSReadLine 2.1+ with Predictive IntelliSenseLink