Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use CTRL + D to exit and CTRL + L to cls in Powershell console

I am trying to make

CTRL + D - exit Powershell console

and

CTRL + L - clear the screen

like in bash.

So far, I have seen that we can define

function ^D {exit} 

but that means I have to do CTRL+D and then hit enter for it to work.

Also, it doesn't even let me define

function ^L {exit} 

Is there anyway to add these key bindings in the default Powershell console?

like image 348
manojlds Avatar asked Dec 02 '11 17:12

manojlds


People also ask

How do you exit Windows PowerShell?

To end a Windows PowerShell session in a Command Prompt window, type exit . The typical command prompt returns.

How do I run a shortcut in PowerShell?

From the Run BoxPress Windows+R to open the Run dialog box, and then type “powershell” in the text box. You can either click “OK” (or press the Enter) to open a regular PowerShell window, or press Ctrl+Shift+Enter to open an elevated PowerShell window.

Which is the shortcut key combinations to get the syntax of any command function in PowerShell?

Now, type cd and press F8. This time around, PowerShell will display the command cd c:\windows . Press F8 a second time and the command cd c:\scripts will be displayed.


1 Answers

Old question, but with PowerShell 5.1 and PowerShell Core 6.x and later:

Set-PSReadlineKeyHandler -Key ctrl+d -Function ViExit 
like image 52
Glenn Avatar answered Sep 20 '22 17:09

Glenn