Mike MJ Harris

Tech Tips - Ctrl R

Share

Techy tech tip - this one for those of your who need to use the terminal. The key combo - `Ctrl-r` (of Cmd-r` for mac users) is super handy in helping you find and reuse commands you've used previously - whether that's a regular, often used one or helping you recall some distant memory of a one of sequence.

Ctrl r in action
`Ctrl-r` in action - a few characters and the option to choose from the past

Quick way to get an old commands

Using the terminal can be super powerful but also tricky. There's no clearly labelled button to click - just an empty line and a cursor. It's up to you to remember or find out what to type.

Fortunately a lot of the commands are the same and repeated. In case you don't have a letter perfect memory or are bored of typing then `Ctrl-r` helps out. It shows you all the previous commands you've used and filters them as you type - all you have to do is remember a few letters.

Why not alias

Aliases are super helpful - you assign a few letters to a command. I find that I use `Ctrl-r` instead of aliases. You don't have to remember a specific couple of letters, you can quickly find similar commands (say git pull, git pull --rebase, git stash && git pull) without having to save and remember different shortcuts. Finally you still see and interact with the actual command rather than a custom to you shortcut - also helpful when pairing where your partner wont have the same aliases as you.

As with most things a personal preference - aliases do a great job. Sometime thought it's that half remembered command you ran ages ago that you need though and that's where `Ctrl-r` comes into it's own. A combo of the two will likely be the sweet spot.

Super charge with fzf

The native `Ctrl-r` works OK but it gets a turbo charge when used with fzf - command line fuzzy finder. Instead of the standard 'one result' you can see a longer history and can navigate with vim bindings.

Summary

Most developers need to use the terminal and in most cases wont have a memory that will store enough shortcuts or commands. Using `Ctrl-r` makes it much easier to reuse commands - whether a standard git command or that super complex sed/grep chain you spent ages creating. It's all there a few key strokes away.