diff --git a/PSReadLine/SamplePSReadLineProfile.ps1 b/PSReadLine/SamplePSReadLineProfile.ps1 index 997b2cc8..94158eb7 100644 --- a/PSReadLine/SamplePSReadLineProfile.ps1 +++ b/PSReadLine/SamplePSReadLineProfile.ps1 @@ -562,6 +562,7 @@ Set-PSReadLineKeyHandler -Key Alt+j ` [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt() } +# Auto correct 'git cmt' to 'git commit' Set-PSReadLineOption -CommandValidationHandler { param([CommandAst]$CommandAst) @@ -579,3 +580,22 @@ Set-PSReadLineOption -CommandValidationHandler { } } } + +# `ForwardChar` accepts the entire suggestion text when the cursor is at the end of the line. +# This custom binding makes `RightArrow` behave similarly - accepting the next word instead of the entire suggestion text. +Set-PSReadLineKeyHandler -Key RightArrow ` + -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]::AcceptNextSuggestionWord($key, $arg) + } +}