Live data from Hacker News

Shell Tricks That Make Life Easier (and Save Your Sanity)

blog.hofstede.it

111–120 of 287 posts

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#111

Using the terminal becomes much more cozy and comfortable after I activate vim-mode. A mistake 3 words earlier? No problem: 3bcw and I'm good to go. Want to delete the whole thing? Even easier: cc I can even use v to open the command inside a fully-fledged (neo)vim instance for more complex rework. If you use (neo)vim already, this is the best way to go as there are no new shortcuts to learn and memorize.

This reminds me of an excerpt from an old Emacs manual: . . . if you forget which commands deal with windows, just type @b[ESC-?]@t[window]@b[ESC]. This weird command is presented with such a benevolent innocence as if it's the simplest thing in the world. I think the better advice for command-line editing would be to set up the mouse.

> This weird command is presented with such a benevolent innocence as if it's the simplest thing in the world.

I think it's a question of context and familiarity. To a vim user, like me and, I assume, ahmedfromtunis, their examples do indeed seem simple and natural. Presumably, to an emacs user, the example you quote (if it's quoted literally—I don't use emacs and can't even tell) is just as natural, and assuming some comfort with emacs is presumably OK in a manual for the software!

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#112

There's one thing you need to only think about once, and has the potential to save you a ton of time: profile your ZSH startup time! Stuff like NVM or Oh My ZSH will add a few seconds to your shell startup time.

good call

if you care about perf, fnm is better/faster/cleaner than nvm. (also, mise is able to manage "all the things", not just node)

IME omzsh slowness usu relates to overloading it w plugins, which I've never found a need for...

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#113

Using the terminal becomes much more cozy and comfortable after I activate vim-mode. A mistake 3 words earlier? No problem: 3bcw and I'm good to go. Want to delete the whole thing? Even easier: cc I can even use v to open the command inside a fully-fledged (neo)vim instance for more complex rework. If you use (neo)vim already, this is the best way to go as there are no new shortcuts to learn and memorize.

I've been a (n)vim user for 20+ years now, but I hate vi-mode in the shell. However if I feel that I need to do a complex command, I just do ctrl-x+e to open up in neovim (with EDITOR=nvim set). I find it a good middle ground.

It’s strange. I have heard this from lots of others too. I think I am an anomaly here. I can’t live without shell vi mode

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#115

Earlier quoted context omitted.

> cc Doing control+o in insert mode temporarily places you into normal mode so that you can execute one normal-mode command, and then go back to insert mode again--no need to hit 'i' again. So, instead of ' cc', ' S'.

The vim version is much easier, if you ask me: 3 strokes, 2 keys and 0 combinations. The one you suggest however requires 4 strokes (ctrl then o then shift then s), 4 keys (ctrl, o, shift, s) and 2 combinations. The "cc" sequence deletes the line and switches automatically to insert mode. To forgo the switch, the sequence then becomes "dd".

S is also a vim sequence. The equivalent readline/emacs is or , or just or if you're already at the end/start of the line.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#116

I'd advise against using sudo !! though since it adds the command to history and then it's very easy to accidentally trigger, running some undesired command as root without any prior confirmation. IMO pressing up, Ctrl-A and typing "sudo " isn't much longer but saves you from running unknown commands as root by accident

i never found !! useful at all when i can just use up arrow to get the entry i want. it becomes more interesting when you can recall older commands, but then too i prefer search because i want to verify what command i am going to run.

and i only use sudo to open a root shell. never to run anything directly. i don't want normal and root commands mixed in the same history.

i could keep sudo commands out of the history, but then i don't have any history for stuff done as root.

with tmux i can switch terminals easily, so i am also not tempted to run things as root that i shouldn't despite having a root shell open.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#117
post #87

One thing I find life-changing is to remap the up arrow so that it does not iterates through all commands, but only those starting with the characters I have already written. So e.g. I can type `tar -`, then the up arrow, and get the tar parameters that worked last time. In zsh this is configured with bindkey "^[OA" up-line-or-beginning-search # Up bindkey "^[OB" down-line-or-beginning-search # Down

Once you start using CTRL+r, you may find that you never reach for up arrow again.

I'm familiar with ctrl-r, but I still very much like the up-arrow behavior described by that commenter.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#118
post #22

Earlier quoted context omitted.

Vi mode is also available in Claude code and gemini-cli to give some recent examples, and a bunch of other places you might not expect it, as well the more obvious places where code is written. Once you get used to it, it is painful to go back.

My biggest complaint about the fish shell is the lack of true vi mode. They attempt to emulate it and it works to some degree, but it's no comparison to readline's implementation.

You can always use Alt-E to open the command line in $EDITOR if you need more powerful commands. I find it better to use readline for small changes and jumping to vim for bigger ones.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#119
post #66

Another useful "Emergency exit" is CTRL+Z which stops the process and cannot be intercepted. It's often faster than hitting CTRL+C and waiting for process cleanup, especially when many resources are used. Then you can do e.g. `kill -9 $(jobs -p)` to kill the stopped tasks.

All of the keyboard-driven terminal signals can be intercepted; catching INT (^C) for cleanup is just more common than the others. Only KILL and STOP cannot be caught.

^Z sends TSTP (not STOP, though they have the same default behavior) to suspend; some programs catch this to do terminal state cleanup before re-raising it to accept the suspension. Catching it to do full backout doesn't make as much sense because the program anticipates being resumed.

^\ sends QUIT, which normally causes a core dump and is rarely caught. If you have core dumps disabled (via ulimit -c 0 or other system configuration) then you can often use it as a harder version of ^C; this is how I would tend to get out of ‘sl’ in places where I found it unwantedly installed.

Post reply on HN