Comment by phforms
17 hours ago
The thing with a lot of these tricks is that you have to get into the habit of using them. I knew `Ctrl+r` for history since I learned about the command line. I even have a nice shell integration with fzf. But I still used the up/down arrow keys for years or scrolled up when I was looking for a previous command, because I never remembered the shortcut and just took the path of least resistance to find something.
Usually what I do is writing these tricks down to a document that is easily accessible at a place where I know that I will look for when failing to remember them. I have a directory of docs where I write stuff like this down by language/tool/etc., so I can quickly look it up without having to search the internet. But I also have to actively remind myself that these things exist whenever I have a problem, stop me from just doing the inefficient thing.
I’ve read that if you’re trying to overturn a habit with a new habit, it’s best to undo whatever it is you did the old way, then redo it the new way.
So if you want to use ctrl-r, but you’re using the up key, use the down key to navigate back to a clear line, then use ctrl-r. Do it enough times and your brain will work overtime to find a shortcut (aka just doing it the new way).
Temporarily binding the up arrow in the shell to echo "Use Ctrl-R" is probably the quickest way to un-/re-learn
I’ve done this, nowadays asking Claude to rebind things so that I’m forced to learn. It comes with interesting side effects!
I learned to type `ls` properly the first time, every time, shortly after installing `sl`.
> But I still used the up/down arrow keys for years or scrolled up when I was looking for a previous command
It's not even that bad of a habit with zsh either where it will only scroll through history matching a substring in your history, for instance if I type "rg -i" and then start pressing up arrow, it will only cycle through history entries starting with "rg -i".
if you enable history substring search in zsh you can get that feature anywhere in the command and not just the start. it's very useful if you remember some snippet of the command like it had the word debug in it etc. in fish that is built in and on by default.
though one function that i recently added will narrow your history down based on a space separated set of filters which i found useful
use `hgrep ruby debug foo` would filter for a line that contained all the words ruby, debug and foo.
This is a readline feature. You can enable it in bash (and other shells?) with:
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
Clearly I am missing some setting. On zsh on macOS and I tried what you just said and it doesn't work like this
FWIW I'm also on macos 15.7.9, zsh 5.9, oh-my-zsh - and I do get this behavior (TIL).
type eg "rg" then up or down arrow, and the history shown is filtered by that rg prefix.
1 reply →
I was missing it too. Google says it's a builtin zsh feature but mac doesn't turn it on by default, so you add these to `~/.zshrc`
So far it works. Thank you diath.
1 reply →
I was my most effective when I had a bunch of cheat sheets taped up in my workspace.
Hot-desking killed this practice. I now get desk anxiety on my in-office days
I am young enough that my entire career has been markdown files, screenshots, and photos on my phone. I (a)sync everywhere by pushing git lfs commits to my home server.
Seems like overkill until it saves my ass. It continues to do so almost half a decade into all the LLM hype. It hits the sweet spot between simplicity, convenience, reliability, and precision.
People strongly underestimate how good the git life can be, especially with all the blogspam on here trying to dethrone it lately.
1 reply →
Have an AI agent compile the cheat sheets into a searchable website hosted on Github for your own personal reference.
2 replies →
reminds me of the time when you got strips of fn key binding cheat sheets for various popular software packages like lotus 123 and wordperfect, and keyboards came with a space to hold them.
Bonus: if you write all your tricks in a document, people will love your document. Whenever I offer a new student my CHEATSHEET.md file, their eyes absolutely light up.
You have a link? :-) (Still a student)
atuin kind of fixes this habit, when you click up you get a list of the latest commands, and you can just start typing to search. It's extremely natural.
Or you can start typing and press up arrow to search with that. Atuin (or some Zsh extensions, etc.) fix the bad UI of having to remember a different key for "search history by order and text" and "search history by order".
I found atuin way too hard/slow to use, I think I went two days before I nuked it and went back to pure omzsh. Has it gotten any better in the past 2ish years?
(hi! I work on atuin!)
yes, it's improved a lot in the last couple of years! what in particular bothered you?
3 replies →
I've been using it happily for longer than that! I do remember having to tweak the default search behaviours when I first installed it but it's been largely problem free ever since.
You just have to do it so often that you’re annoyed by it and then you learn the shortcut and then you force yourself to always do the shortcut.
That's how I learned Emacs!
being annoyed and forcing yourself is how everyone learns Emacs
Usually what I do is writing these tricks down to a document that is easily accessible at a place where I know that I will look for when failing to remember them.
People had this same problem last century. They would use templates that fit over their keyboards with all the common shortcuts and commands printed on them. Sometimes they were for a specific program, but you could buy blank ones to write your own notes.
Today, "keyboard templates" have an entirely different meaning, so the best thing for this is paper. Print your shortcuts out on a piece of paper and put it near your monitor. You could even categorize them by writing them on different-colored Post-Its.
It's quite true. Years ago, after `git switch` was released, I wanted to try to switch from `git checkout` to `git switch`. Ultimately I had to set up some bash nastiness to error and "scold" me when I typed `git checkout` from memory, while still allowing shell scripts to call `git checkout` just fine. It was a fun exercise, and at least now I know how I could do it again: https://github.com/lelandbatey/dotfiles/blob/99c08f81fc89710...
What's the point of switching to switch? I've only ever used checkout and not sure what I am missing out on.
Your beef is with git, which is terrible, not a shell.
https://atuin.sh/