What is a keyboard shortcut for closing a Windows PowerShell window?
I have opened an empty Windows PowerShell window, and have not yet entered any commands into the window. The default, unchanged directory is my user account folder. I want to close the window with a keyboard shortcut.
Does NOT work:
Ctrl+w (adds the text ^W into the editor)
Ctrl+d (adds the text ^D into the editor)
Alt+F4 (does nothing)
exit followed by Enter (works, but is a cumbersome sequence)
Is there any native solution to this problem without using an AutoHotkey script? I am using Windows 10.
Top Answer/Comment:
While Alt+Space then C works as pointed out above without any changes, it still requires two keystrokes. You can define your own exit shortcut in PowerShell 5.0 and up by adding a Set-PSReadLineKeyHandler command to your Powershell profile. While this does require editing your PS Profile, once set up it works for all future sessions of PowerShell. As an example,
Set the execution policy of PowerShell as admin:
Set-ExecutionPolicy RemoteSigned
Open a PowerShell terminal window and type the following to edit your PowerShell Profile file:
code $Profile
This will open your Powershell profile. If you'd like this to work for all users, edit the AllUsers profile which is located at $PROFILE.AllUsersCurrentHost. For more information on the PowerShell profile see this Microsoft reference page.
Add the following to the first line of the profile (ViExit is only available in PS 5.1):
Set-PSReadLineKeyHandler -Chord 'Alt+F4' -Function ViExit
This defines the Alt+F4 as the exit key command. If you'd like to use Ctrl+d (not D) instead use this line:
Set-PSReadLineKeyHandler -Chord 'Ctrl+d' -Function DeleteCharOrExit
Now close the PowerShell terminal and reopen. The shortcut keys defined above (Alt+F4 or Ctrl+d as applicable) should now work.
상단 광고의 [X] 버튼을 누르면 내용이 보입니다