Skip to content

Instantly share code, notes, and snippets.

@skipcloud
Last active January 27, 2020 09:20
Show Gist options
  • Select an option

  • Save skipcloud/cda6268c6688af5838c48615e7ca55b8 to your computer and use it in GitHub Desktop.

Select an option

Save skipcloud/cda6268c6688af5838c48615e7ca55b8 to your computer and use it in GitHub Desktop.
Some shell shortcuts.

I've always been quite the fan of keyboard shortcuts, after all why move your hand to the mouse to dick around clicking things if you can just do the same thing without moving your fingers from the home row. In my eyes the arrow keys might as well be on the other side of the room. Did you know your shell has a bunch of shortcuts to make your life a little easier? A library called readline[1] is responsible and I think all of these work on Mac too but your milage may vary.

  • Move back through your history with ctrl-p
  • Move forward through your history with ctrl-n
  • Need to incrementally search through your history? ctrl-r has got you, you can keep pressing ctrl-r to see it's suggestions. Slight sidebar, if you have fzf[2] installed it extends this functionality showing you what it has found.
  • Are there a bunch of commands that you ran in a sequence before that you want to run again? Before I used to keep pressing up up up until I found what I needed, pressed enter, then repeated this horribly inefficient cycle. Try this, search for the first one with ctr-r then press ctrl-o to run it, the next command in your history will be preloaded onto the command line for you. You can keep pressing ctrl-o to run each command and load the next.
  • ctrl-e to jump to the end of the command line
  • ctrl-a to jump to the start of the command line
  • ctrl-b to go back one character
  • ctrl-f to go forward one character
  • alt-f to go forward one word
  • alt-b to go back one word.
  • ctrl-u to delete everything from your cursor to the start of the line.
  • ctrl-w to delete one word
  • ctrl-h to delete one letter

There are a LOT more short cuts, especially if you have meta key support enabled in your terminal (for example meta-u will upcase the word you're on).

Hope people find those useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment