Yeah! Why is editing a command you already typed in so weird. Why is it that half the time pressing backspace instead adds a bunch of weird extra characters, or that you can’t navigate using arrow keys, and so on?!
Fun fact: you can use C-A and C-E to go to the start or end of a line, no need to reach all the way over to Home or End… maybe if you aren’t using a vim mode terminal anyway.
Basically you can sort by how much processing the terminal/program is doing.
The most basic is stuff like cat or nc or other stuff that doesn’t have anything. Things you get for free, regardless of the interface, are: 1. typing 2. backspacing 3. C-W to delete a whole word 4. C-U to delete a whole line 5. C-C to interrupt, C-Z to suspend and so on…
You can see all the control codes your terminal (emulator) supports using stty -a
There’s a GNU library called readline
that does a lot of work for you and it’s widely available and used. It does things like supporting C-E or End to go to the end, C-A/Home, C-
Bash uses this, as do lots of other things. Nifty!
You can wrap anything in readline using rlwrap
. That’s helpful.
btw, the shortcuts do from emacs. go figure.
Or the program could be using another input library, like libedit. Then all bets are off! Python recently added multiline editing support to its REPL interface, which is very nifty.
And of course there’s all the TUIs which implement their own interface, like editors, shells, REPLs and other things.
If you get comfy using like the 5 most basic readline shortcuts, you can get pretty far. Maybe I should do that, and move away from fish shell… readline has its own vi mode so i can still have the most wonderful way of moving a cursor around :))
So this explains why different programs do different, weird, things when you press keys. It all depends what input system/library they’re using.
I wanna know how clipboards work and also ssh/tmux and so on please!