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
    0
    ·
    edit-2
    6 months 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).

  • balsoft@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    6 months ago

    I think this is one of many un-features in Linux world where

    • It would benefit a beginner
    • It sounds simple but actually quite complicated to get right (especially if you aim to keep compatibility with things)
    • Anyone possessing the skills to implement it neither needs it nor cares about it

    As such, for you individually, I suggest just getting more comfortable with tmux (or zellij) and vi-like keybinds for text manipulation. Once you learn those (and set your readline mode to vi), you won’t look back. Oh, also, try Ctrl+x Ctrl+e in bash, it might help.

    Or switch to emacs and using it as a terminal emulator. In that case you will have to learn and use emacs keybindings, but the selection semantics in the “terminal” will be the same as in the “editor”.

    • podbrushkin@mander.xyzOP
      link
      fedilink
      English
      arrow-up
      0
      ·
      6 months ago

      one of many un-features in Linux

      What exactly? Shift-selection is already possible with Blesh. I think I’ve seen scripts for synchronizing buffer with clipboard. And everything else is a matter of redefining existing shortcuts.

      I’ve heard about Linux being highly customizable and decentralized OS, and suddenly I can’t define my own shortcuts because there is a list of un-features?

      I don’t care about Vi and Emacs, I already have my workflow and I’m trying to transfer it to Linux. When I will succeed, then (maybe) I will spend some time to explore other ways of interacting with terminal. Otherwise, it’s not freedom, it’s becoming a victim of OS.

      • balsoft@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        6 months ago

        I’ve heard about Linux being highly customizable and decentralized OS, and suddenly I can’t define my own shortcuts because there is a list of un-features?

        You can customize it to do whatever you want. Heck, you can write your own terminal emulator that does exactly what you need. But some things can be harder to do than others and require skills and experience. Once someone implements those harder things, they become a “feature”. Before then, therefore, they are an “un-feature”. See https://xkcd.com/1349/

        E.g. it is probably possible to set up your shell to use shift-selection for the command you’re currently editing, but shift-selection for the output of a previous command will require terminal support. You will have to make sure that the two don’t interfere with each other, which can be quite complicated.

        I already have my workflow and I’m trying to transfer it to Linux

        Linux is a different OS that, by default, does things differently from others. You can configure it to emulate some other UX, but it won’t necessarily be easy. In the meantime, you can install the micro editor, set EDITOR=micro, and then Ctrl+x Ctrl+e in bash to edit the command in a more familiar setting.

        • podbrushkin@mander.xyzOP
          link
          fedilink
          English
          arrow-up
          0
          ·
          6 months ago

          I’m fine, I got what I wanted. Apparently, it isn’t un-feature of Linux, it’s un-feature of ReadLine which is shipped with Bash.

    • ChaoticNeutralCzech@feddit.org
      link
      fedilink
      English
      arrow-up
      0
      ·
      6 months ago

      Add Windows-like Alt codes to the list. They’re not perfect (they use a DOS codepage and A-F in the Unicode extension clash with shortcuts in other programs like Firefox, although not passing them through via xkb would solve this) but people use them a lot, especially in my country. At? Alt+64. Backtick? Alt+96. Caret? Alt+94. Hash? Alt+38. Musical note? Alt+13. Yes, we can type most of these on the Czech layout with AltGr but people don’t know this and/or prefer things that work on the commonly default English layout too.

      • balsoft@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        6 months ago

        I prefer compose keys because they are easier to remember.

        Oh, also, I think GTK apps have that Ctrl+shift+U thing which allows you to enter characters by code. Never really got used to it though.

        • ChaoticNeutralCzech@feddit.org
          link
          fedilink
          English
          arrow-up
          0
          ·
          edit-2
          6 months ago

          I’m getting used to Compose and AltGr. Unexpected Keyboard for Android helps learn compose codes by visualizing them but it’s still a bit of resistance. And yes, Compose can also be used to input Unicode hex codes.

          Either way, I created a custom layout for AltGr and Shift+AltGr layers that is more convenient for me than remembering Compose and Unicode codes.

  • TurboWafflz@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    6 months ago

    I think if we want something like that to be consistent everywhere we need to stop using Ctrl so much as a modifier for non-terminal tasks. It doesn’t solve everything, but using Alt or Super for copy and paste like Haiku and MacOS do is a big step in the right direction. It’s just hard to change an established custom without making the whole experience less consistent

    • podbrushkin@mander.xyzOP
      link
      fedilink
      arrow-up
      0
      ·
      6 months ago

      It’s nice to see you think of it as of movement towards consistency. I also look at it this way.

      But what is it about Ctrl? Text editing is historically the main task of computers, and Ctrl is the main “modifier” key. To me it seems fair it’s dedicated for some text editing shortcuts. Probably they are consistent since 1980’s.

      • pr06lefs@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        6 months ago

        but ctrl-c to cancel terminal tasks predates the 1980s. the inconsistency came in when apple decided to ignore that precedent and introduce ctrl-c, ctrl-x, and ctrl-v as shortcuts in their graphical UI.

        to achieve consistency, probably better to invent a new terminal type that does away with the accumulated cruft of 50 years. problem is you would also need new cli programs to go with it.

        • Alaknár@sopuli.xyz
          link
          fedilink
          English
          arrow-up
          0
          ·
          6 months ago

          Your comment reads extremely weird, considering both Mac and Windows handle this with zero issues.

          It’s super simple: if you’re in Select mode (any text is selected), Ctrl+C copies. In any other case, Ctrl-C is the cancel command.

  • coltn@lemmy.ml
    link
    fedilink
    English
    arrow-up
    0
    ·
    6 months ago

    I think most of this works for me in zsh. But also tmux can help with selection; I believe by default you use your prefix then open bracket (Ctrl-b + [) to put your self in selection mode. I have some configs to use vim bindings in selection mode.

    Tmux selection:

    # Yanking
    bind-key -T copy-mode-vi v send-keys -X begin-selection
    bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
    bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
    

    zsh keybinding:

    # Key Bindings
    # set vim mode
    bindkey -v
    
    # create a zkbd compatible hash;
    # to add other keys to this hash, see: man 5 terminfo
    typeset -g -A key
    
    key[Home]="${terminfo[khome]}"
    key[End]="${terminfo[kend]}"
    key[Insert]="${terminfo[kich1]}"
    key[Backspace]="${terminfo[kbs]}"
    key[Delete]="${terminfo[kdch1]}"
    key[Up]="${terminfo[kcuu1]}"
    key[Down]="${terminfo[kcud1]}"
    key[Left]="${terminfo[kcub1]}"
    key[Right]="${terminfo[kcuf1]}"
    key[PageUp]="${terminfo[kpp]}"
    key[PageDown]="${terminfo[knp]}"
    key[Shift-Tab]="${terminfo[kcbt]}"
    
    # setup key accordingly
    [[ -n "${key[Home]}"      ]] && bindkey -- "${key[Home]}"       beginning-of-line
    [[ -n "${key[End]}"       ]] && bindkey -- "${key[End]}"        end-of-line
    [[ -n "${key[Insert]}"    ]] && bindkey -- "${key[Insert]}"     overwrite-mode
    [[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}"  backward-delete-char
    [[ -n "${key[Delete]}"    ]] && bindkey -- "${key[Delete]}"     delete-char
    [[ -n "${key[Up]}"        ]] && bindkey -- "${key[Up]}"         up-line-or-history
    [[ -n "${key[Down]}"      ]] && bindkey -- "${key[Down]}"       down-line-or-history
    [[ -n "${key[Left]}"      ]] && bindkey -- "${key[Left]}"       backward-char
    [[ -n "${key[Right]}"     ]] && bindkey -- "${key[Right]}"      forward-char
    [[ -n "${key[PageUp]}"    ]] && bindkey -- "${key[PageUp]}"     beginning-of-buffer-or-history
    [[ -n "${key[PageDown]}"  ]] && bindkey -- "${key[PageDown]}"   end-of-buffer-or-history
    [[ -n "${key[Shift-Tab]}" ]] && bindkey -- "${key[Shift-Tab]}"  reverse-menu-complete
    
    # Finally, make sure the terminal is in application mode, when zle is
    # active. Only then are the values from $terminfo valid.
    if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
    	autoload -Uz add-zle-hook-widget
    	function zle_application_mode_start { echoti smkx }
    	function zle_application_mode_stop { echoti rmkx }
    	add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
    	add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
    fi
    
    
    # History - use current line up to cursor to search through history with arrow keys
    autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
    zle -N up-line-or-beginning-search
    zle -N down-line-or-beginning-search
    
    [[ -n "${key[Up]}"   ]] && bindkey -- "${key[Up]}"   up-line-or-beginning-search
    [[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-beginning-search
    
  • Arthur Besse@lemmy.mlM
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    6 months ago

    “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.

    What terminal emulator are you using where ctrl-c copies instead of sending SIGINT when text is selected? In every one I’ve ever used, ctrl-c still sends SIGINT even with text selected (and one must must use ctrl-shift-C/ctrl-shift-V to copy/paste).

    I don’t have any suggestion for getting the behavior you’re asking for, but besides the normal ctrl-(shift)-C/V clipboard FYI you also have two other types of clipboard-like things: one which works anywhere (not only in the terminal) and is actually always automatically copying anything you select and lets you paste from it with middle click (this originated with X Windows but i think most Wayland compositors have also implemented it by now), and another which is found in GNU Readline (used by bash and numerous other REPLs) called the “kill buffer” which can be pasted (or “yanked”) from and cut (or “killed”) to using Emacs keyboard shortcuts (which also include various cursor movement controls).

    Notes:

    • the kill buffer is local to a given readline context, it’s not shared across different shell windows.
    • the list of emacs keybindings in that wikipedia article i linked is currently confusingly referring to the kill buffer as “the clipboard”
    • you can drastically reconfigure your readline keybindings and other behavior by editing your .inputrc file, but you cannot achieve what you were originally asking for because there is no concept of text selection in readline.

    HTH!

    • podbrushkin@mander.xyzOP
      link
      fedilink
      arrow-up
      0
      ·
      6 months ago

      What terminal emulator are you using where ctrl-c copies instead of sending SIGINT when text is selected?

      This is what I experienced in conhost.exe (legacy windows console experience, predecessor of Windows Terminal) + Powershell. In windows terminal it works this way too. This is why I suspect it’s related not to terminal itself (conhost.exe/wt.exe/gnome terminal etc), and not to specific shell (bash/powershell), but to an extension for shell (ReadLine,PSReadLine).

      As for various types of buffers and clipboards, I always felt like one system-wide clipboard with clipboard history is enough. When I cut something from terminal, quite often I paste it into another app, and not back to terminal.

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      0
      ·
      6 months ago

      What terminal emulator are you using where ctrl-c copies instead of sending SIGINT when text is selected?

      I know that the terminal emulator built into the JetBrains IDEs works that way…

  • felsiq@piefed.zip
    link
    fedilink
    English
    arrow-up
    0
    ·
    6 months ago

    I have everything you mentioned (except maybe the selection only stuff, I don’t use it and forget if I set it up at all) set up in my zsh+kitty setup, so it’s definitely possible. If you want I can dig thru my zshrc and kitty config for the relevant parts once I’m at my pc later.

    People in here saying it’s a bad idea for things like compatibility with other shells make some good points, but I think they’re missing one important aspect - fuck other shells, what do I care? 95% of my time in the terminal is spent on my own machine and I may as well make it convenient for myself. The odd time I ssh into another box without my keybinds I’ll be a bit less efficient, but that’s a worthwhile trade off imo.

    • podbrushkin@mander.xyzOP
      link
      fedilink
      arrow-up
      0
      ·
      6 months ago

      In Gnome Terminal: Ctrl+arrows work, Ctrl+delete work, home/end work, Ctrl+backspace — not, and there is no text selection, of course. So, something is working as expected without config at all, and for what isn’t working, config will not help.

      • felsiq@piefed.zip
        link
        fedilink
        English
        arrow-up
        0
        ·
        6 months ago

        I never set up text selection and have apparently never tried it till now so that one I can’t help with, but with zsh you can enable ctrl+backspace behaviour by putting bindkey “^H” backward-delete-word in your ~/.zshrc file. Ctrl+delete is bindkey “\e[3;5~” delete-word, in case you also use that one.

  • Remus86@lemmy.zip
    link
    fedilink
    arrow-up
    0
    ·
    6 months ago

    I know in zsh, fish, and nushell, you can press a key combo to jump into a text editor of your choice. You write your command there, with all the power and shortcuts in emacs, vim, nano (whatever you like to use). Then you save and exit, and it appears in your command line, ready to execute.

  • Blaiz0r@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    6 months ago

    I feel your pain, the only one’s I know are…

    • CTRL+a = cursor to beginning of line
    • SHIFT+CTRL+c = Copy
    • SHIFT+CTRL+x = Cut
    • SHIFT+CTRL+v = Paste
    • Alaknár@sopuli.xyz
      link
      fedilink
      English
      arrow-up
      0
      ·
      6 months ago

      You can add:

      • CTRL+K = delete everything from the cursor to the right.
      • CTRL+U = delete everything from the cursor to the left.
      • rgalex@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        6 months ago

        And just to complement those, CTRL+Y to “yank” back whatever was deleted with CTR+K or CTRL+U.

  • iopq@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    6 months ago

    I would just like my inputs to be separate from the outputs. Anyone write a split pane thing?