question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make `ForwardChar` configurable to accept whole suggestion or the next word of it

See original GitHub issue

Loving new the suggested line - just on quite small problem, and I half expect the answer to be “We know, we’re working on it”, but I couldn’t see it in the open issues.

Environment

PS version: 7.0.1
PSReadline version: 2.1.0-beta2
os: 10.0.18362.1 (WinBuild.160101.0800)
PS file version: 7.0.1.0
HostName: ConsoleHost (Windows Terminal)
BufferWidth: 172
BufferHeight: 39

I don’t think this is version dependent - apart from needing this version of PSReadLine,

Steps to reproduce

  1. Start Powershell (7) and allow PSRL 2.1.0 beta 2 to load normally, then run Set-PSReadLineOption -PredictionSource History

  2. Start typing a line from the history and see that it is suggested. Press right arrow to accept the line and then us left and right to move forwards and backwards along the line. Run or escape from the command.

  3. Run Get-PSReadLineKeyHandler | where function -Match "accept" AcceptSuggestion and AcceptNextSuggestionWord are not listed

  4. run Get-PSReadLineKeyHandler | where key -Match "rightarrow" only the normal cursor movements are listed.

  5. I would like right arrow to be accept next word and ctrl+rightarrow or end to be accept all so I run

set-PSReadLineKeyHandler -Function AcceptNextSuggestionWord -Chord RightArrow
set-PSReadLineKeyHandler -Function AcceptSuggestion -Chord ctrl+RightArrow

  1. Run Get-PSReadLineKeyHandler | where Key -Match "rightarrow" again these keys have lost their normal behavior

  2. Verify that accept suggestion by work or whole line works, select left works, but select right doesn’t

Expected behavior

A key can work inside and outside “suggestion” mode (as with the default right arrow.).

Actual behavior

It can’t

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jhoneillcommented, Jun 10, 2020

Excellent , thank you.
Accept next suggestion word functionality does not seem to be linked to ForwardWord, so I have gone back to the default of right arrow accepting the line, with a version of your example to make ctrl+right work

0reactions
silverqxcommented, May 20, 2021

Also, the ask can be easily satisfied by implementing a custom script block key binding, such as the one below.

Thank you 🙏, your code snippet script block helped me a lot, I used it like this:

# Accept the current inline suggestion
Set-PSReadLineKeyHandler -Key End -ScriptBlock {
       param($key, $arg)

       $line = $null
       $cursor = $null
       [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)

       if ($cursor -lt $line.Length) {
           [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine($key, $arg)
       } else {
           [Microsoft.PowerShell.PSConsoleReadLine]::AcceptSuggestion($key, $arg)
       }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Announcing PSReadLine 2.1+ with Predictive IntelliSense
AcceptNextSuggestionWord is built within the function ForwardWord , which can be bound with Ctrl+f by Set-PSReadLineKeyHandler -Chord "Ctrl+f" ...
Read more >
How to set tab for zsh autocompletion?
I think you have one more space or something, I have copy pasted and it wasn't working. The best way is to directly...
Read more >
zsh-autosuggestion: rebind and undo?
I'm new to this plugin (and ignorant to shell programming) and, for some reason, I often find myself hitting the forward-char key and...
Read more >
As A Geek, How I Customized My Visual Studio Code ...
# This custom binding makes `RightArrow` behave similarly - accepting the next word instead of the entire suggestion text. Set- ...
Read more >
handle fish key bindings — fish-shell 3.6.1 documentation
forward-char. move one character to the right; or if at the end of the commandline, accept the current autosuggestion. If the completion pager...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found