Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update powershell keyboard bindings to be emacs style like bash shell

I'm fairly familiar with the default bash shell shortcuts (emacs style). For example, if I want to move my cursor forward by a word I would press Alt+F (same as you would in emacs). I can get to the previous command with Ctrl+P.

Is it even possible in windows powershell to override these shortcuts? If so, does anyone know of a good way to map the default bash shell shortcut configurations to powershell (in a bash shell you can say set -o emacs, for example)?

If it helps, I don't really care about powershell per say, I care about posh-git shell. However, git-shell inherits its properties from powershell from what I can tell.

like image 992
Matt Messersmith Avatar asked Apr 08 '17 14:04

Matt Messersmith


1 Answers

You can do that with the PSReadLine module which ships with PowerShell 5.0 (Windows 10).

Simply set the EditMode option to Emacs:

Set-PSReadLineOption -EditMode Emacs

In addition to the default Windows mode, it also has a Vi mode.

The project README file mentions that neither are fully implemented so don't expect full feature parity, but I can confirm that it switches tab completion to bash-style and supports the Alt+F and Ctrl+P key bindings for moving forward and jumping to the previous command respectively

(I'm not an experienced emacs user so I'm unable to tell whether this comes "close enough" to what you expect)

like image 137
Mathias R. Jessen Avatar answered Nov 09 '22 20:11

Mathias R. Jessen