Powershell Auto Complete Settings – How to Configure

powershell

I was wondering if there was anyway to change the way the current powershell autocomplete works. I have been using bash and had changed them to offer a few features that I'd like in my powershell experience.

Currently powershell as I'm writing a command with a folder it will tab autocomplete and also cycle through my folders. This works how I like but one feature that I miss is using partial matching of a command and hitting the up key and it would find that command that matches the rest of what I do.

So Id write 'echo test'
Then id write other commands and try 'ec' and tap up and 'echo test' would complete and not the last command I typed

Just wondering if there is anyway anyway to get this back?

Best Answer

One feature that I miss is using partial matching of a command and hitting up

You can use PSReadLine (A bash inspired readline implementation for PowerShell) for this:

PSReadLine

This module replaces the command line editing experience in PowerShell.exe for versions 3 and up. It provides:

  • Syntax coloring
  • Simple syntax error notification
  • A good multi-line experience (both editing and history)
  • Customizable key bindings
  • Cmd and emacs modes (neither are fully implemented yet, but both are usable)
  • Many configuration options
  • Bash style completion (optional in Cmd mode, default in Emacs mode)
  • Bash/zsh style interactive history search (CTRL-R)
  • Emacs yank/kill ring
  • PowerShell token based "word" movement and kill
  • Undo/redo
  • Automatic saving of history, including sharing history across live sessions "Menu" completion (somewhat like Intellisense, select completion with arrows) via Ctrl+Space

...

To set your own custom keybindings, use the cmdlet Set-PSReadlineKeyHandler. For example, for a better history experience, try:

Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

With these bindings, up arrow/down arrow will work like PowerShell/cmd if the current command line is blank. If you've entered some text though, it will search the history for commands that start with the currently entered text.

Source PSReadLine