Readline
Who never got into this kind of situation?
42sh$ cp some/enormous/wrong/path/until/a/directory some/new/place/. # Wups, I forgot the '-r' again
You might want to directly go back to the beginning of the line, as you would do in your editor. This section is here to answer those questions, and boost your terminal=using skills.
The following commands will ring a bell if you\'re an emacs
user. A
vi
mode is also available, but rarely used. You\'ll have to stay in
emacs
mode for the whole first semester.
Remember that every time you delete some text, it is stored inside what is called \'prev\'.
You have time, so open a terminal and try these commands:
Essentials
Command | Meaning |
---|---|
Ctrl-a | Move the cursor to the start of the line |
Ctrl-e | Move the cursor to the end of the line |
Ctrl-u | Delete everything from the cursor back to the line start |
Ctrl-k | Delete everything from the cursor to the end of the line |
Ctrl-w | Delete word until after the previous word boundary |
Ctrl-y | Yank/Paste previously deleted text at the cursor position |
Ctrl-r | Incrementally search the line history backwardly |
Ctrl-_ | Undo the last editing command |
Ctrl-l | Clear the screen, reprinting the current line at the top |
Alt-. | Yank/Paste last arg of previous command at the cursor position |
Moving around
Command | Meaning |
---|---|
Ctrl-b | Move the cursor one character to the left |
Ctrl-f | Move the cursor one character to the right |
Alt-b | Move the cursor one word to the left |
Alt-f | Move the cursor one word to the right |
Cut, copy
Command | Meaning |
---|---|
Alt-d | Delete word until before the next word boundary |
Alt-y | Rotate through all previously deleted text (once you have pressed Ctrl-y) |
History
Command | Meaning |
---|---|
Ctrl-p | Move in history one line before this line |
Ctrl-n | Move in history one line after this line |
Ctrl-g | Abort an incremental search (Ctrl-r) and restore the original line |
Changing text
Command | Meaning |
---|---|
Ctrl-t | Swap characters under cursor |
Alt-u | Uppercase the current word |
Alt-l | Lowercase the current word |
All of these shortcuts are associated with the readline library. Meaning that you can use them with any program that uses [readline]{.title-ref}, such as [gdb]{.title-ref}, [python]{.title-ref}, [bash]{.title-ref}, etc...