Equivalent of bash's Ctrl-r in PowerShell
does anybody knows of a way to have the backward command search feature of bash [Ctrl-r]
(and [Ctrl-o]
) that are so useful, in windows powershell ?
C-r
is a more powerful arrow up
history manipulation, it is like emacs's C-r
in that it searches backward inside the commands you previously entered. Then C-o
executes that command and immediately places on the line the next command after that. So that you can repeat passed series of commands efficiently. Also it looks up into a saved history, not a session history. (~/.bash_history
file). Which is infinitely useful.
thanks.
ps: as a bonus the tab completion not working by cycles would be awsome also.
Type first letters of the command and press F8.
Alternatively you can press F7 and type first letters.
More details: http://technet.microsoft.com/en-us/magazine/ff678293.aspx
WMF 5.0 RTM, which includes Windows PowerShell 5, now supports the same reverse command search feature of bash CTRL+R
. I have been using this in Windows 10 Anniversary Edition, and my bash muscle memory is very happy.
The support actually comes from the PowerShell module PSReadLine which I see was mentioned in some of the comments of the question. The good thing is that PSReadLine now appears to be included in the base WMF 5.0 installation, at least it is on Windows 10.
If you are running PowerShell 3 or later, you can also install PSReadLine as well and get the history search feature.
Note: I've not found out how to get this working in ISE as CTRL+R
is mapped to something else (Show/Hide Script Pane).
To manipulate your history you may use the history cmdlets, list them by this command:
Get-Command *-history
Searching your history is done like this, feel free to make a function to shorten it:
Get-history | Select-String "command"
function f ($Name) { Get-history | Select-String $name }