Skip to content

Commit

Permalink
Add an key binding example: ForwardCharAndAcceptNextSuggestionWord (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
daxian-dbw authored Jun 10, 2020
1 parent 2005773 commit ba3ebf2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions PSReadLine/SamplePSReadLineProfile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
}

0 comments on commit ba3ebf2

Please sign in to comment.