Here’s a list of shortcuts I use frequently to make my time on the bash command line prompt a bit more efficient. Some disclaimers …
- Although, I am a vim user who never quite attained the precise finger deftness demanded by emacs and yes, I do know about the vim command line editing mode for bash. However, I have realized that the vim mode is even more painful than most of the emacs-inspired (or rather readline specific) shortcuts listed here.
- This is not a comprehensive list of shortcuts for bash. These are just the ones I find useful but have difficulty remembering sometimes due disuse (which causes muscle memory loss).
- Some of these are not required if you are using a capable terminal (for example, if the terminal maps the Home and End keys correctly, those can be used instead of C-a and C-e respectively … however, this is what causes the muscle memory loss mentioned earlier).
Note: C == Ctrl, M == Meta (or Alt)
Misc:
- Tab for command and filename completion
- C-l to clear the screen
- Up and down arrow keys for browsing command history one at a time
Moving about:
- C-a or “Home” to move to start of line– C-e or “End” to move to end of line
- M-b to move a word backward
- M-f to move a word forward
Deleting:
- C-k to delete till the end of line
- M-backspace or C-w to delete a word backwards
- M-d to delete a word in place
Searching and inserting:
- C-r begin searching backwards for matching string
- C-M-y insert argument from last command here
- M-. cycle through last arguments of previous commands
if …
$ echo foo bar
$ echo xxx yyy
then
$ echo “M-.” yields yyy, another “M-.” yields bar
Major editing:
- C-X C-E to edit the current command using $EDITOR
Well, that’s about all I can remember right now ! Thanks for reading.