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?


Solution 1:

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

Set-PSReadlineKeyHandler -Key ctrl+d -Function ViExit

Solution 2:

There is a new library PSReadline for Powershell v3.0 that emulates the GNU Bash tab completion and key bindings. Even CTRL + R for reverse incremental search works. Exactly what I wanted.