Reputation: 813
I've recently upgraded PowerShell to version 7.3.0 version and now, when I type a command, I see its suggestions like when I'm typing pip
it adds list
like in this image. Or when I type start of the command it suggests its full name.
The problem is that when I press Tab it doesn't complete the command, instead it just starts listing current directories, i.e. here is an image after pressing Tab once.
Also even when I start typing the full name of the command like pip li
it still shows the ending, but when pressing Tab it just does nothing.
I expected this to complete the current command with the suggestion after Tab is pressed.
I've tried to google this problem but haven't found the exact same case I have with 7.3.0 version.
Upvotes: 71
Views: 19994
Reputation: 15856
TL;DR Answer
For devs who use VSCode on Windows
code $PROFILE // usually under C:\Users\$USERNAME\OneDrive\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
Set-PSReadLineKeyHandler -Key Tab `
-BriefDescription ForwardCharAndAcceptNextSuggestionWord `
-LongDescription "Move cursor one character to the right in the current editing line and accept the next word in suggestion when it's at the end of current editing line" `
-ScriptBlock {
param($key, $arg)
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
if ($cursor -lt $line.Length) {
[Microsoft.PowerShell.PSConsoleReadLine]::ForwardChar($key, $arg)
} else {
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptSuggestion($key, $arg)
}
}
This will make press TAB accepts the new full line suggestion. Feel free to change the map to whatever key you prefer
Please note this will change the default behavior of tab giving suggestions to available files in the directory when running any command that targets these files
Upvotes: 1
Reputation: 5181
i think you can use :
Set-PSReadLineKeyHandler -Key Ctrl+q -Function TabCompleteNext
i grabbed this line from "this line in PSReadLine github"
Upvotes: 0
Reputation: 1286
Just press -> (right arrow) key
If you want to change key bindings: source: https://devblogs.microsoft.com/powershell/announcing-psreadline-2-1-with-predictive-intellisense/
Key Bindings for Predictions
Key bindings control cursor movement and additional features within the prediction. To support users running Predictive IntelliSense on multiple platforms, key bindings are user-settable from the command line or your profile script.
PSReadLine
contains functions to navigate and accept predictions. As an example, to accept a displayed prediction, PSReadLine contains functions:
- AcceptSuggestion – Accept the current inline suggestion
- AcceptNextSuggestionWord – Accept the next word of the inline suggestion
AcceptSuggestion
is built withinForwardChar
, which by default is bound to RightArrow. Pressing RightArrow accepts an inline suggestion when the cursor is at the end of the current line.
AcceptNextSuggestionWord
is built within the functionForwardWord
, which can be bound with Ctrl+f bySet-PSReadLineKeyHandler -Chord "Ctrl+f" -Function ForwardWord
. Pressing Ctrl+f accepts the next word of an inline suggestion when the cursor is at the end of current editing line.As a user, you can bound other keys to
AcceptSuggestion
andAcceptNextSuggestionWord
for similar functionalities. Search forForwardCharAndAcceptNextSuggestionWord
inSamplePSReadLineProfile.ps1
for an example to make RightArrow accept the next word from inline suggestion, instead of the whole suggestion line.List of additional suggested key bindings defined in
PSReadLine SamplePSReadLineProfile.ps1
Upvotes: 117