In all GUI text editors, web browsers and IDE’s you can move a cursor:

  • left/right arrows - move by char;
  • ctrl+left/right - move by word;
  • home/end - move to start/end of line.

Add Shift to any of above combination and everything you jumped through now is selected and you can: Ctrl+C, Ctrl+X,Delete to copy/cut/delete selection.

Also, you can Ctrl+Delete and Ctrl+Backspace to delete a next/previous word.

Also, you can Ctrl+Home/End to jump to start of first line or end of last line.

I want this to work when I type in a command in my Terminal.

Is it possible in Linux? It’s a vanilla experience in Windows+Powershell, thanks to default PSReadlLine extension. It works both in conhost.exe and in Windows Terminal, but doesn’t work in WT + cmd.exe, which makes me think it’s PSReadLine which is responsible for this technological perfection.

“But you can’t copy with Ctrl+C, it’s…” - You can. When something is selected It copies selection to clipboard, otherwise it sends SIGINT.

I’m not bound to any distro or terminal application, but right now I don’t see these incredible text editing techniques working even in Ubuntu+Powershell+PSReadLine, to say nothing about the Bash. I’ve tried installing WezTerm, but it doesn’t have text selection either, at least by default. And I’m inclined to think it has nothing to do with terminal emulators at all, since it works in conhost.exe+Powershell.

  • Oinks@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    5
    ·
    edit-2
    19 hours ago

    There’s apparently a ZSH plugin for this with a quite a few stars, though I haven’t used it and can’t speak for how well it works. In other shells what you want just doesn’t exist to my knowledge, though it should be possible to script it with enough effort.

    The problem is that in the terminal you always have at least two layers of input handling in the terminal emulator and the shell. And these layers talk to each other by emulating a 70s VT100. This leads to some issues, in no particular order:

    • Terminal emulator keybindings will step on shell keybindings, and the shell will never know about it because it can’t actually see the keys being pressed.
    • Even if the terminal doesn’t care about a key, it might be impossible or error-prone to detect anyway. This applies to surprisingly regular keys like Tab.
    • As you’ve noticed some terminals try to get clever and do things like making Ctrl-C copy if you’ve selected text. The shell doesn’t know about this either.
    • Most shells and TUI apps have selection modes. These are independent from terminal selections.
    • There’s no standard way of using the clipboard in Linux, but multiple different ones that may or may not work.

    All of these problems gets worse if you add multiplexers like tmux by the way.

    Now it would be possible to write a bespoke terminal emulator and shell combination that unifies selection and makes all the reasonable keybindings actually work. There are attempts at this, such as the Emacs Eshell. Unfortunately Emacs people don’t quite share your idea of what reasonable keybindings look like (and it’s also a little bit broken, though for mostly unrelated reason).

    Ultimately though the main reason this is an unsolved problem is that most Linux users just get used to the regular Readline line editor that all commonly used shells ship with. Complex edits can always be done in your $EDITOR (via C-X C-E in Bash).