Live data from Hacker News

Small programming tricks

will-keleher.com

151–160 of 192 posts

Re: Small programming tricks

#151
Those were not programming tricks, but computing tricks or command line/sql tricks.

Anyways I find it mind boggling how many useful actions are not known by „normal people”. Most people are really using computers in a very inefficient way.

My idea is if we would spend time making people learn computers or software they use daily better - we wouldn’t need AI agents and we would triple GDP.

Re: Small programming tricks

#152
post #93
post #77

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. Usua…

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".

Re: Small programming tricks

#153

Earlier quoted context omitted.

There are several keyboard shortcuts that you would never find out from watching an agent, but are mindblowing to new Linux users. I suck at remembering vim keybindings, but I have ingrained ctrl+a ctrl+e for jumping to the start/end of a string (which also works all over OS X). I had been a developer for an embarassing amount of time before I discovered those. There are other terminal specific shortcuts for removing…

Another one, not quite as handy but still awesome: ctrl s / ctrl-q. This freezes/unfreezes the terminal output so you can read it, without interrupting your program. Useful for very fast walls of text.

I remember when the Pause key did that! It's long enough ago that I don't remember which systems did so, and most laptops don't even have a Pause key any more, but it was often very handy for reading fast-moving console output.

Re: Small programming tricks

#154

The most useful shell trick I've used to date is mapping the 'cd' command to 'zoxide', which is a more powerful version of cd that remembers folders you've been to.

Is it much more powerful, than pushd?

Yes, because you don't have to pop in order. "zoxide " is "search the history of working directories for a path ending in and cd to that".

Re: Small programming tricks

#155
post #151

Those were not programming tricks, but computing tricks or command line/sql tricks. Anyways I find it mind boggling how many useful actions are not known by „normal people”. Most people are really using computers in a very inefficient way. My idea is if we would spend time making people learn computers or software they use daily better - we wouldn’t need AI agents and we would triple GDP.

Maybe, but there's all sorts of habits and skills that would make us enormously more productive/healthy/etc. if only the masses would learn them. This is a very old problem.

Re: Small programming tricks

#156
post #134

Earlier quoted context omitted.

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

Have an AI agent compile the cheat sheets into a searchable website hosted on Github for your own personal reference.

Re: Small programming tricks

#157
post #134

Earlier quoted context omitted.

Hot-desking killed this practice. I now get desk anxiety on my in-office days

Have an AI agent compile the cheat sheets into a searchable website hosted on Github for your own personal reference.

and hook up a Bluetooth sensor so when you walk into the office it prints them off in individual sticky notes and assigns one of the humanoid robots to collect them and stick them on the monitor or cubicle walls of your chosen work desk.

what a time to be alive.

Re: Small programming tricks

#158

Additional tip: In the macOS terminal you can... Ctrl + Option + - ...and it'll undo your typing. Dunno about other OS keys!

Didn’t know about that one, and can’t find any references, but works in my fish

I’ve always used Ctrl+U, it’s an Emacs shortcut, so it works in many shells and other prompts (especially since readline supports it) by default.

(For example Ctrl+Opt+- doesn’t seem to work in the Python REPL whereas Ctrl+U does.)

Re: Small programming tricks

#159
post #120
post #86

Earlier quoted context omitted.

> 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".

Clearly I am missing some setting. On zsh on macOS and I tried what you just said and it doesn't work like this

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.

Re: Small programming tricks

#160
post #77

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. Usua…

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.
Post reply on HN