Reputation: 32162
I'm using the powershell VI mode via
Set-PSReadlineOption -EditMode vi
It is awsome to be able to edit the line using VI commands however there is one thing that is annoying. When using the up and down arrows to navigate history the cursor always starts at the start of the line instead of at the end. ie: if I had the following command in my history
svn help x-shelve --list
then I would want the cursor (represented by the pipe | ) to be like
svn help x-shelve --list|
rather than
|svn help x-shelve --list
is there a way to set this?
Upvotes: 5
Views: 2840
Reputation: 191
Use the same Set-PSReadLineOption
cmdlet that you used to get into VI mode:
Set-PSReadLineOption -HistorySearchCursorMovesToEnd:$true
You can see which options can be set with Get-PSReadLineOption
:
Get-PSReadLineOption
and the online documentation includes a few useful examples
Upvotes: 7
Reputation: 2929
You can use the Set-PSReadLineKeyHandler
cmdlet:
Set-PSReadLineKeyHandler -Key UpArrow `
-ScriptBlock {
param($key, $arg)
$line=$null
$cursor=$null
[Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchBackward()
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
[Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition($line.Length)
}
Set-PSReadLineKeyHandler -Key DownArrow `
-ScriptBlock {
param($key, $arg)
$line=$null
$cursor=$null
[Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchForward()
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
[Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition($line.Length)
}
Upvotes: 2