‹ BackHN Continuity

Thread

Small programming tricks

681 points · 294 comments · signa11

  1. phforms · · focus · HN ↗
    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.

    1. diath · · focus · HN ↗
      > 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".

      1. harikb · · focus · HN ↗
        Clearly I am missing some setting. On zsh on macOS and I tried what you just said and it doesn't work like this
        1. applicative · · focus · HN ↗
          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`

              bindkey '^[[A' history-search-backward
              bindkey '^[[B' history-search-forward
          
          So far it works. Thank you diath.
          1. saghm · · focus · HN ↗
            I'm not really sure what "turn it on by default" even means in the context of a shell. I've had that manually in my config for years.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.