11

I use Bash and PowerShell interchangeably, and find it quite annoying when I can't do a Ctrl+R on my PowerShell Console.

Is there a plugin/alternate command that can help me switch between Bash and PowerShell seamlessly?

Update (2018)

PowerShell now supports Ctrl + R. Please see this answer.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Srikanth Venugopalan
  • 9,011
  • 3
  • 36
  • 76
  • Related: For all PowerShell history of all time, see *[How can I see the command history across all PowerShell sessions in Windows Server 2016?](https://stackoverflow.com/questions/44104043)* – Peter Mortensen Dec 18 '18 at 07:09

3 Answers3

17

An alternate command is to type e.g #ls and press Tab keep pressing tab to cycle through all command history that starts with ls.

In previous versions you could type ls then F8 to match history. Keep pressing F8 to cycle through multiple matches.

Note:ls is just a placeholder in this case. Replace it with any command you want.

Mwiza
  • 7,780
  • 3
  • 46
  • 42
Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • Thanks, but isn't this applicable to just the current session? it doesn't seem to work when I close PS console and reopen.. – Srikanth Venugopalan Aug 15 '13 at 05:26
  • 1
    There are techniques for saving the history using Get-History | Export-CliXml $home\pshist.clixml and the PowerShell EngineExiting event. You can then reload that history using Import-CliXml $home\pshst.clixml | Add-History. That can get quite large over time though so you would probably want to limit the size of the history saved out. – Keith Hill Aug 15 '13 at 06:19
9

As of today PowerShell supports the Ctrl + R shortcut.

Simply press Ctrl + R when in the PowerShell console and start typing any part of a command you have run before.


Alternatively:

Start typing part of a command you have run before, and press or hit F8.

Keep pressing F8 to cycle through similar commands.

Mwiza
  • 7,780
  • 3
  • 46
  • 42
  • Note that this does **not** work with PowerShell ISE, just with vanilla (boring) PowerShell. – NH. Feb 22 '18 at 18:52
5

Take a look at PSReadline: https://github.com/lzybkr/PSReadLine

This module supports interactive history search in emacs mode and you can bind Ctrl+R to ReverseHistorySearch in Windows mode if you prefer.

The long term goal of PSReadline is to make it much easier to switch from bash to PowerShell w.r.t. command line editing while providing a PowerShell experience, e.g. tab completion.

Jason Shirk
  • 7,734
  • 2
  • 24
  • 29