Is there a way to get vim keybindings in powershell as you would in bash or zsh with a command like
set -o vi
Is there a way to get vim keybindings in powershell as you would in bash or zsh with a command like
set -o vi
PSReadline module provides this.
To install is simple not sure what the requirements are but I think at least windows 10 for this method provided. If you dont have OneGet or not sure you can follow the instructions at PSReadline
To install PSReadline without elevating privileges
Install-Module PsReadline -Scope CurrentUser
Check you have a powershell profile
Test-Path $PROFILE
If you don't create one
New-Item -Type File $PROFILE
Open $PROFILE in ISE
ise $PROFILE
Add this line
Set-PSReadlineOption -EditMode vi
Reload $PROFILE or just restart powershell
& $PROFILE
The modern answer is PSReadLine (1.2+). To enable the bindings in your current session:
Set-PSReadlineOption -EditMode vi
You may also want to add a visual indicator for insert or command mode with:
Set-PSReadLineOption -ViModeIndicator Cursor
To permanently use these settings in future sessions, add the command to your $Profile with a text editor (e.g. notepad $Profile, or code, edit etc...). If you don't have a profile, you can create one with:
New-Item -ItemType File -Path $PROFILE -Force
For more information on how Vi mode works check the lengthy article on DeepWiki
PowerShell 7.4.2 shipped with v2.3.5. If you want the latest version or are on an older version of PowerShell you can install or update via the PS Gallery:
Install
Install-Module -Name PSReadLine -Force
Update
Update-Module -Name PSReadLine -Force
Note PSReadline is not automatically loaded in PowerShell 7+ if a screenreader is detected (as it doesn't play nice with them). You can still manually load it.
I wouldn't swear that there isn't an undocumented feature of Powershell that allows this, but as far as I know the answer is no. At least I have never seen anything in Powershell documentation to suggest it's possible.
JR
As it happens, you can load PowerShell syntax-highlighting into VIM. It's what I use for script development.
http://www.vim.org/scripts/script.php?script_id=1327
While it isn't in the shell itself, it's handy for building longer scripts. I have one window in VIM, and have a PowerShell prompt in another. I find it very handy.
The powershell engine now offers the hooks to make this relatively straightforward but I don't know of anyone who has done it yet.
The PSReadln project has an emergant emacs mode, though it is in its infancy. Adding a vi mode in PSReadln would be the obvious thing to do but I don't have time to devote to it.