3

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?

Biswapriyo
  • 11,584
Ray
  • 481

4 Answers4

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.

postanote
  • 5,136
2

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.

NotTheDr01ds
  • 28,025
0

One possible solution is to use PowerShell and integrate the Linux commands into Windows as if they were native applications.

The procedure is not simple, and is documented in the Microsoft blog
Integrate Linux Commands into Windows with PowerShell and the Windows Subsystem for Linux.

The complete source code described in the article as well as additional help for incorporating it into your workflow is available at https://github.com/mikebattista/PowerShell-WSL-Interop.

harrymc
  • 498,455
-1

The standard WSL consoles all support Ctrl-Shift-c (copy) and Ctrl-Shift-v to paste (not enabled by default, go into Properties and check the option to enable this, and note that this also works in PowerShell and CMD prompts). You can also copy text by selecting it then right-clicking with the mouse). In addition, you can use Ctrl-Shift-Enter to toggle full screen mode, and you also have all of the power of bash within a bash console, so for example:

Tab    Autocomplete commands
Ctrl + r   Search the history of commands used
Ctrl + a / e  Move to start / end of current line
Alt + f / b   Move to the next / previous word
Ctrl + u / k  Cut all text on the left / right side of the cursor
Ctrl + w   Cut the word on the left side of the cursor
Ctrl + d   Logout of Terminal or ssh (or tmux) session,   Ctrl + l   Clear Terminal

Note Ctrl u / k. Also note Alt-Left/Right (with cursor keys) to jump between words.

It can also be nice to learn some tmux with it's great pane manipulation tools:

C-b : (to enter command mode), then  :ls, :help, :set mouse on  (or other commands)
C-d  (Note: no C-b first!)  (Detach from a session, or C-b d or C-b D for interactive)
'M-' stands for 'Meta' key and is the Alt key on Linux
C-b ?  (list all key bindings)   C-z  (Suspend tmux)   C-q  (Unsuspend tmux)
tmux a (Attach last session)    tmux a -t mysession   (Attach to mysession)
tmux ls (list sessions),  tmux a (attach),   tmux a -t <name> (attach named session)
tmux  (start tmux),   tmux new -s <name>,   tmux new -s mysession -n mywindow
tmux kill-session –t <name>     (kill a session)   tmux kill-server  (kill tmux server)

***** Panes (press C-b first): " (Split new pane up/down) % (Split new pane left/right) z (Toggle zoom of current pane) x (Kill current pane) { / } (Swap current pane with previous pane / next pane) t (Show the time in pane) q (Display pane indexes) ! (Break current pane out of the window) m (Mark current pane, see :select-pane -m) M Clear marked pane Up/Down/Left/Right (Change pane in cursorkey direction, must let go of Ctrl) C-Up/Down/Left/Right (Resize the current pane in steps of 1 cell, must hold down Ctrl) M-Left, M-Right (Resize current pane in steps of 5 cells) o (Go to next pane in current window) ; (Move to the previously active pane) C-o (rotate panes in current window) M-o (Rotate panes backwards) M-1 to M-5 (Arrange panes preset layouts: tiled, horizontal, vertical, main-hor, main-ver)

***** Windows (press C-b first): c (Create a new window) , (Rename the current window) 0 to 9 (Select windows 0 to 9) ' (Prompt for window index to select) s / w (Window preview) . (Prompt for an index to move the current window) w (Choose the current window interactively) & (Kill the current window) n / p (Change to next / previous window) l (Change to previously selected window) i (Quick window info in tray)

***** Sessions (press C-b first): $ (Rename the current session) ( / ) (Switch 'attached' client to previous / next session) L Switch the attached client back to the last session. f Prompt to search for text in open windows. r Force redraw of the attached client. s (Select a new session for the attached client interactively) ~ Show previous messages from tmux, if any. Page Up Enter copy mode and scroll one page up. Space Arrange the current window in the next preset layout. M-n Move to the next window with a bell or activity marker. M-p Move to the previous window with a bell or activity marker.

***** Buffers (copy mode) [ (Enter 'copy mode' to use PgUp/PgDn etc, press 'q' to leave copy mode) ] (View history / Paste the most recent text buffer)

(List all paste buffers = (Choose a buffer to paste, from a list)

  • Delete the most recently copied buffer of text.

C-Up, C-Down M-Up, M-Down Key bindings may be changed with the bind-key and unbind-key commands.

You have vastly more options in WSL to manipulate the console than in PowerShell in fact.

YorSubs
  • 1,087