I have Powershell Core 6 installed on my Windows 10, and I'm using WSL (Windows Subsystem for Linux) with Ubuntu 18.04 LTS. I like the Powershell 6 terminal, it supports a lot of the keyboard shortcuts you'd expect in a text editor, things like ctrl-backspace for deleting whole words and stuff like that; it even supports ctrl-home and ctrl-end for deleting til beginning and deleting til end respectively. The WSL terminal however, is dire in comparison. It doesn't even support ctrl-v for paste!!! I have to use right mouse click every time.

I know how to install Powershell on Linux, but even so, I still have to use Powershell under that terminal. Is there a way to use the normal Powershell (under Windows), but for my Ubuntu 18.04 in WSL?


Solution 1:

Old question that got bumped today with another answer (that's on track).

Short Answer

The biggest misunderstanding with the question itself is (as @Biswapriyo pointed out in edits and comments) is the confusion between shell and terminal.

No, you can't run "WSL" in a "PowerShell terminal" because there's no such thing as a "PowerShell terminal" (see below).

Some shell equivalents to the hotkeys, at least:

Feature PowerShell Bash/Zsh
Delete Previous Token Ctrl+Backspace Ctrl+W
Delete to beginning of line Ctrl+Home Ctrl+U
Delete to end of line Ctrl+End Ctrl+K

Explanation

When you run WSL, you are running a shell. This is bash by default, but could be zsh, or fish, or any of a myriad of others.

PowerShell is also a shell.

These shells run in a terminal, which is the window that presents the shell to you. By default in Windows 10, all shells run in the legacy "Windows Console" by default. This appears to be what you are running (at least at the time you asked the question).

Other terminals could include the PowerShell ISE (pretty much replaced in favor of Visual Studio Code, in my understanding), or Windows Terminal (installable from the Windows Store). There are quite a few others as well. When you install a different terminal, PowerShell (as a shell) can run in that terminal, as can your WSL shell, as can the CMD shell.

Side note: Windows Terminal is designed to be the replacement for Windows Console, and eventually (in Windows 11) should be able to be set as the default console.

When you press a key or key-chord (e.g. Ctrl+End), that key goes through:

  • Windows, which first checks to see if there are any handlers for it (e.g. Alt+F4 to send the "Exit" command to an app. Or if you have something like AutoHotkey installed, the key you press could get handled there first.

  • Then Windows passes it to the terminal. The terminal may choose to handle it.

    For example, Alt+Enter is handled by the Windows Console, regardless of whether your shell is CMD, PowerShell, Bash in WSL, or anything else. When that hotkey is pressed, the terminal will toggle between a normal Windows and Fullscreen-mode.

    There are actually very few keystrokes that Windows Console itself handles. Most go on to the next step. However, if you select the application menu (click on the icon in the upper left) and go to Properties, you can enable Ctrl+C and Ctrl+V for copy/paste.

    Windows Terminal is quite different, and handles many more keys by default. Furthermore, you can configure almost all of them. For instance, by default, a newly installed Windows Terminal does bind Ctrl+V to paste.

    But Ctrl+Home, Ctrl+End, and Ctrl+Backspace have nothing to do with the terminal. This is what @Biswapriyo was trying to help you understand in the edits and comments.

  • If it's not handled by Windows or the terminal, the keypress finally gets to the shell itself.

    Since Windows Console does not handle Ctrl+V, the shell receives it. CMD and PowerShell are Windows applications, and can talk to the Windows clipboard directly, so they can trap the Ctrl+V, retrieve the text from the clipboard, and insert it onto the command-line.

    On the other hand, bash is a Linux application running under the Linux kernel. It doesn't know how to talk to the Windows clipboard. That's why it relies on the terminal for this.

    Further, Ctrl+V has a well-established meaning in most Linux shells, and that usage predates (I believe) even the Windows usage. See this question and the first answer there for details.

    For the other editing keys, as @YorSubs pointed out in that answer, there are equivalents. And if something isn't bound by default in your shell of choice, it's almost always configurable.

Solution 2:

The hotkey you reference are not unique to the PowerShell v6+ terminal. You've been able to do this since PowerShell has been around. Heck even cmd.exe has these keyboard hotkeys for years now.

Have you looked at/considered using/tried the new 'Windows Terminal' for your use case?

The point folks are delivering here is that WSL exists to address Linux interactive cmd line use case specifically, not really PowerShell specific stuff. If MS does not provide a way to do what you are after, then you need to look to 3rdP.

Windows Terminal settings file - configure to what you'd like, in accordance with the docs.

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation

{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

    "profiles":
    [
        {
            // Make changes here to the powershell.exe profile
            "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
            "name": "Windows PowerShell",
            "commandline": "powershell.exe",
            "hidden": false
        },
        {
            // Make changes here to the cmd.exe profile
            "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
            "name": "cmd",
            "commandline": "cmd.exe",
            "hidden": false
        },
        {
            "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
            "hidden": false,
            "name": "Azure Cloud Shell",
            "source": "Windows.Terminal.Azure"
        }
    ],

    // Add custom color schemes to this array
    "schemes": [],

    // Add any keybinding overrides to this array.
    // To unbind a default keybinding, set the command to "unbound"
    "keybindings": []
}

See: Style your Windows terminal and use WSL and PowerShell like a pro This blog specifically talks to Ubuntu config with it.

See also, Micorosft's other free editor -

Developing in WSL The Visual Studio Code Remote - WSL extension lets you use the Windows Subsystem for Linux (WSL) as your full-time development environment right from VS Code. You can develop in a Linux-based environment, use Linux-specific toolchains and utilities, and run and debug your Linux-based applications all from the comfort of Windows.