Skip to main content

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

CommandMeaning
Ctrl-aMove the cursor to the start of the line
Ctrl-eMove the cursor to the end of the line
Ctrl-uDelete everything from the cursor back to the line start
Ctrl-kDelete everything from the cursor to the end of the line
Ctrl-wDelete word until after the previous word boundary
Ctrl-yYank/Paste previously deleted text at the cursor position
Ctrl-rIncrementally search the line history backwardly
Ctrl-_Undo the last editing command
Ctrl-lClear the screen, reprinting the current line at the top
Alt-.Yank/Paste last arg of previous command at the cursor position

Moving around

CommandMeaning
Ctrl-bMove the cursor one character to the left
Ctrl-fMove the cursor one character to the right
Alt-bMove the cursor one word to the left
Alt-fMove the cursor one word to the right

Cut, copy

CommandMeaning
Alt-dDelete word until before the next word boundary
Alt-yRotate through all previously deleted text (once you have pressed Ctrl-y)

History

CommandMeaning
Ctrl-pMove in history one line before this line
Ctrl-nMove in history one line after this line
Ctrl-gAbort an incremental search (Ctrl-r) and restore the original line

Changing text

CommandMeaning
Ctrl-tSwap characters under cursor
Alt-uUppercase the current word
Alt-lLowercase 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...