I noticed bash has a short cut for ctrl+T which swaps the last two characters before the cursor.
I'm wondering why the engineers decided to include this.
Is there a practical purpose that this might be commonly used for?
I noticed bash has a short cut for ctrl+T which swaps the last two characters before the cursor. I'm wondering why the engineers decided to include this. Is there a practical purpose that this might be commonly used for? |
||||
It's very useful to quickly fix typos:
becomes
with a single CtrlT. You can use AltT to swap words too (e.g. when switching between |
|||||
|
This is inherited (by readline) from GNU Emacs, which uses control-T for transposing characters: https://www.gnu.org/software/emacs/manual/html_node/emacs/Transpose.html Note that bash's line editor defaults to Emacs mode, but you can also switch it to vi mode, if you prefer. |
||||
|
This key combination, a binding inherited from the It may seem vain to have a binding for such a seldom used feature that be easily achieved with a few more key strokes. Old timers such as I use it quite often and it used to save some transmission time back in the days of 300 baud modems, in the late '70s, especially in the middle of long lines. A similar and more useful command, bound to Alt+T, transposes the words at the left and at the right of the cursor. T was chosen because it is the initial letter of transpose. Other bindings with similar origin include:
These bindings, implemented in the GNU readline package, are therefore available in all programs that use it for user input, such as bash, but also gdb, bc, ... Some of the are also available in other environments: The Firefox URL input line, text input fields in the OS/X graphical interface, and many X-based window managers. vim users can select the corresponding bindings via an environment variable. |
|||
|
It is vrey useufl for corretcing smiple tpyos wehre yuo haev accidnetally trasnposed piars of lettres. (Having severe RSI in both wrists, I end up using this a lot, personally...) |
|||
|
A very quickly fix typos. effects the immediate 2 corrector block before the courser. If you typed This works if you have a space after hyphen & then do Ctrl + T |
|||
|
bash
, as such, butreadline
(which bash uses for input at the prompt). Your bash is usingemacs
key-bindings; you can change to vi key-bindings if your an Editor Wars partisan ;) sanctum.geek.nz/arabesque/vi-mode-in-bash There's a couple of "cheat-sheets" forreadline
here: readline.kablamo.org/emacs.html and readline.kablamo.org/vi.html. – John N 13 hours agoreadline
ChangeLog
hints at this. So originally the shortcut was handled in Bash itself, albeit briefly, before being pulled out intoreadline
— but the shortcut came to Bash from Emacs (I don't know if it was invented in Emacs or came from elsewhere). – Stephen Kitt 11 hours ago