Readline basics
Every developer should learn some basics of GNU Readline. Readline allows you to edit commands. It pops up in a lot of places. Knowing the basics will make your life much easier.
You have probably encountered the GNU Readline library or a readline-like library many times because it is used by a lot of applications to allow users to edit command lines. The most basic functionality is going through the history of commands with the up- and down-arrow.
Some applications that I frequently use that use readline are the following are the most popular UNIX shells, most interactive REPLs for programming languages, many command line database clients. Currently I’m using a lot of Ubuntu with Bash, Python and MongoDB. But you will likely find readline in many other stacks as well.
Most people will have found the up- and down-arrows for nagivating history and the TAB button for autocomplete. After that the first commands I recommend learning are listed below.
Getting around
- Ctrl-a move to the beginning of the line
- Ctrl-e move to the end of the line
- Alt-b move back one word
- Alt-f move foward one word
Editing
- Ctrl-k delete everything starting from the cursor
- Ctrl-u delete everyting before the cursor
- Alt-d delete till the end of the word
- Ctrl-_ undo last operation
- Alt-r undo all changes
History
- Ctrl-p goto the previous command
- Ctrl-n goto the next command
- Ctrl-r search backwards through history, type a search string and keep pressing Ctrl-r to find the command you are looking for
Replacements
Some of these shortcuts also can be done with other keys. You can use the arrow keys to go back in history, you can use the delete and backspace key to delete characters, words and lines. You can use Home and End to get around. The biggest advantage of these shortcuts is that they will allow you to keep your hands on the alphanumeric area of the keyboard.
Further
This is not meant to be an exhaustive set of command, but with just these commands your efficiency will improve a lot. When you are ready for more just Google a cheatsheet. You are now well on your way to becoming a readline wizard and getting around comfortably on a compact mechinical keyboard. 😄