While Alt+Space
, then c
works as pointed out above without any changes, it still requires two key strokes. You can define your own exit shortcut in PowerShell 5.0 and up by addding 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,
-
Open a PowerShell terminal window and type the following to edit your PowerShell Profile file:
notepad $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 PS 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 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.
参考:https://superuser.com/questions/1388293/what-is-a-keyboard-shortcut-for-closing-a-windows-powershell-window