How to change the Suggestion completion key on Powershell 7.3.0?

2.3k views Asked by At

Recently I updated my PowerShell to version 7.3.0 and when typing it shows suggestions. But when I press the Tab key it doesn't autocomplete the suggestion. How to set the Tab as the autocompletion key?

2

There are 2 answers

5
Nirmal Code On BEST ANSWER

So after doing some research I found out,

  • The default autocompletion key is the RightArrow key.
  • You can accept the suggestions word by word
  • You can change the suggestion view type between InlineView and ListView by pressing F2

Source: Using predictors in PSReadLine

So here's how to change key bindings

Set Tab key as the keybinding for auto complete (AcceptSuggestion)

Set-PSReadLineKeyHandler -Chord "Tab" -Function AcceptSuggestion

Set RightArrow key as the keybinding for accepting the next word in the suggestion (ForwardWord)

Set-PSReadLineKeyHandler -Chord "RightArrow" -Function ForwardWord

Note :

You need to run these each time you open a new session. To avoid that add these to profile.ps1 file. More on Profiles

  • To change these just for the current user,

    Open a PowerShell window and run,

    notepad $profile.CurrentUserAllHosts
    

OR

  • To change these for all users,

    Open a PowerShell window with Run as Administrator and run,

    Notepad $profile.AllUsersAllHosts
    

If the file doesn't exist, create a new one.

Add these lines and save.

Set-PSReadLineKeyHandler -Chord "Tab" -Function AcceptSuggestion
Set-PSReadLineKeyHandler -Chord "RightArrow" -Function ForwardWord
0
Spring Herald On

If you just want to switch the behaviors of Tab and RightArrow, use this:

Set-PSReadLineKeyHandler -Chord "Tab" -Function AcceptSuggestion
Set-PSReadLineKeyHandler -Chord "RightArrow" -Function TabCompleteNext