6

I have recently got myself a new Windows 11 laptop, and started exploring powershell. Never used it before on Windows, but I'm a frequest user of zsh in Mac so not completely new.

I upgraded Powershell to 7.2.1, but noticed that the auto-suggestion type feature that I'm used to with Oh My Zsh is missing. After searching a bit, I installed PSReadLine, and setup my profile using the following:

Import-Module PSReadLine

Set-PSReadLineOption -PredictionSource History

Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

Set-PSReadLineKeyHandler -Key Tab -Function Complete

This is working a lot better than earlier, but I'm noticing that I cannot accept autocompletions partially.

For example, this is part of my history:

New-item –type file –force $profile

If I now try to create a file say test-file, and start typing New-Item, I do get the suggestion. I want to accept till the end of -force, or possibly till file. That's not happening, whatever be the key combination I try (tried Ctrl+, Shift+, Alt+, Fn+ in vain).

Of course, I can accept full suggestion and delete what I do not need. While for this example it's reall doesn't matter, but it'll be annoying for long commands with matches present only in initial parts. So, my question is what is the combo to accept suggestions in part, or if that's need to be enabled separately, how do I do it?

3
  • Related search hit dev.to/ofhouse/… Commented Feb 27, 2022 at 8:08
  • 3
    Have a look at this Set-PSReadLineKeyHandler -Chord "Ctrl+f" -Function ForwardWord learn.microsoft.com/en-us/powershell/module/psreadline/about/… Commented Feb 27, 2022 at 8:10
  • @Daniel Thanks. I changed it to Ctrl+RightArrow, and it seems to be the same behaviour. Do you want to add an answer? I'll accept and close. Commented Feb 27, 2022 at 8:26

1 Answer 1

7

From the about_PSReadLine docs

AcceptNextWordSuggestion
Accepts the next word of the inline suggestion from Predictive IntelliSense. This function can be bound with Ctrl+F by running the following command.

Set-PSReadLineKeyHandler -Chord "Ctrl+f" -Function ForwardWord
Sign up to request clarification or add additional context in comments.

1 Comment

Nicely done. Note that ForwardWord does double duty: it navigates to the next word in the part of the command line that has been typed explicitly and also accepts the next suggested word. AcceptNextWordSuggestion does exist as a separate function and can be bound separately, if desired (probably not worth it). On Windows, where Ctrl+RightArrow is by default bound to NextWord, which only navigates in what has been typed, the following can therefore be used to make it accept the next suggested word too: Set-PSReadLineKeyHandler -Chord 'Ctrl+RightArrow' -Function ForwardWord

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.