1

I am new to Powershell and I am trying to find if I can use ! instead of F8 to scan back through command history and return command that match the text on the command line.

I am using Surface Pro with Type cover, and it is really a pain to type F8 or any F*.

I find ! in Linux really handy and I am wondering if I can change the key-bind or remap the same functionality of F8 to ! instead.

1
  • You could use #text<TAB> to search by PowerShell history.
    – user364455
    Sep 5, 2015 at 18:37

2 Answers 2

1

Install PSReadLine. Add something like the following to your $profile:

if ($host.Name -eq 'ConsoleHost')
{
    Import-Module PSReadline
    Set-PSReadlineKeyHandler -Key '!' -Function ReverseSearchHistory
}

The Set-PSReadlineKeyHandler changes the history-search key from the default value of ctrl+r to !.

1
  • HistorySearchBackward is the exact function F8 is by default btw - not ReverseSearchHistory.
    – Nilzor
    Oct 1, 2017 at 4:49
0

I dont think so. Powershell uses the ! as an alias for the not operator.

The interesting thing is that if you run the alias command, it lists all the built alias's, however ! is not listed. So I do not think it can be remapped. It must be hardcoded, since it used very often.

1
  • I agree with Keltari - ! is treated as conditional negation operator. You could have a look at the PSReadline module though - have a look at the Set-PSReadlineKeyHandler cmdlet.
    – megamorf
    Sep 6, 2015 at 10:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .