Windows Powershell Vim Keybindings

Solution 1:

These days you have a couple of options. With the default console you can just run Vim on Windows (you might already have it if you have git or other tools installed). To make the integration more seamless place this in your PowerShell profile:

$VIMEXEPATH    = "c:\<location>\vim.exe"

Set-Alias vim  $VIMEXEPATH
Set-Alias vi   $VIMEXEPATH

I'd also recommend adding the following to your vimrc file so it executes shell commands with PowerShell itself.

set shell=powershell
set shellcmdflag=-command

Otherwise the only ISE that supports a Vi mode right now is PSReadLine now available on the PS Gallery

There are usage notes but in brief for VI mode you need to add the following line to your ISE profile.

Set-PSReadlineOption -EditMode vi

Note that Vi support was added in 1.2 but 1.1 shipped with Windows 10. You will need to use the -force parameter to update shipping (aka manually installed) version.

Solution 2:

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 dont create one

New-File -Type File $PROFILE



Add this line

Set-PSReadlineOption -EditMode vi

Reload $PROFILE or just restart powershell