⌨️
PowerShell 7.5のキーバインド変更する(Emacs/bash)
目的
WSL2も使うようになってPowershellと併用する機会が増えたので、PowershellでもCtrl+pなどのEmacs/bashなキーバインドを使いたい(体感をそろえたい)
やること
PowershellのプロファイルにEmacsのキーバインドモードのオプションを追加する
環境
- Windows 11 (buildなどは今回はあまり関係ないだろう)
- Powershell 7.5.1
プロファイルの場所の確認
ドキュメントとしてはこちら
$PROFILE | Select-Object *Host* | Format-List
結果はこんな感じ
PS C:\Users\kasumic> $PROFILE | Select-Object *Host* | Format-List
AllUsersAllHosts : C:\Program Files\PowerShell\7\profile.ps1
AllUsersCurrentHost : C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts : C:\Users\kasumic\OneDrive\ドキュメント\PowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\kasumic\OneDrive\ドキュメント\PowerShell\Microsoft.PowerShell_profile.ps1
プロファイルの作成とキーバインドモード変更オプションの設定
VSCodeで開く
code C:\Users\kasumic\OneDrive\ドキュメント\PowerShell\Microsoft.PowerShell_profile.ps1
記述するオプションはドキュメントのこちらを参考に
Microsoft.PowerShell_profile.ps1
Import-Module PSReadline
Set-PSReadLineOption -EditMode Emacs
保存後にターミナルを再起動すると、慣れ親しんだキーバインドが使えるようになっている
ちなみにキーバインドの確認はGet-PSReadLineKeyHandler
で確認できる
Discussion