There's one thing you need to only think about once, and has the potential to save you a <i>ton</i> of time: profile your ZSH startup time!<p>Stuff like NVM or Oh My ZSH will add a few seconds to your shell startup time.
Using the terminal becomes much more cozy and comfortable after I activate vim-mode.<p>A mistake 3 words earlier? No problem: <esc>3bcw and I'm good to go.<p>Want to delete the whole thing? Even easier: <esc>cc<p>I can even use <esc>v to open the command inside a fully-fledged (neo)vim instance for more complex rework.<p>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.
Oh wow I didn't know about this, thank you. The underlying feature is called "readline vi-mode" for folks who want to search more about it.
CTRL + W usually deletes everything until the previous whitespace, so it would delete the whole '/var/log/nginx/' string in OP's example. Alt + backspace usually deletes until it encounters a non-alphanumeric character.<p>Be careful working CTRL + W into muscle memory though, I've lost count of how many browser tabs I've closed by accident...
Set $WORDCHARS accordingly. In your case, remove / from $WORDCHARS.<p><a href="https://unix.stackexchange.com/a/726014" rel="nofollow">https://unix.stackexchange.com/a/726014</a>
> Be careful working CTRL + W into muscle memory though, I've lost count of how many browser tabs I've closed by accident...<p>This hurts.<p>Also, for the shell, if you do C+w, you can "paste" it back using C+y. Assuming you have not removed that configuration.
In my terminal it's the exact opposite – Alt-Backspace deletes to the previous space, whereas Ctrl-W deletes to the last non-alphanumeric (such as /). I'm using fish shell in an Alacritty terminal.<p>Yeah, pressing Ctrl-W accidentially is a pain sometimes ... but Ctrl-Shift-T in Firefox is a godsend.
> Yeah, pressing Ctrl-W accidentially is a pain sometimes ... but Ctrl-Shift-T in Firefox is a godsend.<p>Fun fact: despite having absolutely no menu entry for it, and I believe not even a command available with Ctrl+Shift+P, Vscode supports Ctrl+Shift+T to re-open a closed tab. Discovered out of pure muscle memory.
Ctrl-Shift-T usually brings that tab right back at least
My favourite trick is either commenting out a whole command or placing a comment at the end of a command to make it easier to find in my persistent history (thanks eliben) [0], using the # character.<p>I tried this in zsh and it wasn't the default behaviour which immediately made me nope from the shell altogether, among all the other quirks. I've just been using bash for far too long to switch to something different.<p>[0] <a href="https://eli.thegreenplace.net/2013/06/11/keeping-persistent-history-in-bash" rel="nofollow">https://eli.thegreenplace.net/2013/06/11/keeping-persistent-...</a>
I love this, from a comment on the article:<p><pre><code> He had in his path a script called `\#` that he used to comment out pipe elements like `mycmd1 | \# mycmd2 | mycmd3`. This was how the script was written:
```
#!/bin/sh
cat
```</code></pre>
A similar trick:<p><pre><code> #!/bin/sh
$*
</code></pre>
that's my `~/bin/noglob` file, so when I call a zsh script from bash that uses `noglob`, it doesn't blow up.
What does it provide over<p>mycmd1 #| mycmd2
Yes! That one's going in my $PATH. Such a useful use of cat!
With ctrl+r, if you press it twice, it will autofill the search with whatever you last searched for. pressing it more will go back through the history. Been using that a lot recently when doing docker stuff. ctrl+r, type the container name, keep going until I get the compose build command. ctrl+r, ctrl+r, repeat until the log command. Then I can just mash ctrl+r to get the build and log commands. Ctrl+r is your friend. ctrl+r
What confuses me is that Ctrl+Y "yank" means the opposite of what it means in Vim. Certainly does not help with keeping my sanity.
> cd -: The classic channel-flipper. Perfect for toggling back and forth.<p>And not only cd. Gotta love 'git checkout -'
One trick I use all the time:<p>You're typing a long command, then before running it you remember you have to do some stuff first. Instead of Ctrl-C to cancel it, you push it to history in a disabled form.<p>Prepend the line with # to comment it, run the commented line so it gets added to history, do whatever it is you remembered, then up arrow to retrieve the first command.<p>$ long_command<p><Home, #><p>$ #long_command<p><Enter><p>$ stuff_1
$ stuff_2<p><Up arrow a few times><p>$ #long_command<p><home, del><p>$ long_command
Not a fan of the LLM-flavoured headings, and the tips seem like a real mixed bag (and it'd be nice to give credit specifically to the readline library where appropriate as opposed to the shell), but there are definitely a few things in here I'll have to play around with.<p>One thing I dislike about brace expansions is that they don't play nicely with tab completion. I'd rather have easy ways to e.g. duplicate the last token (including escaped/quoted spaces), and delete a filename suffix. And, while I'm on that topic, expand variables and `~` immediately (instead of after pressing enter).
Speaking of readline, I recently found out PowerShell has a readline mode (<a href="https://learn.microsoft.com/en-us/powershell/module/psreadline/about/about_psreadline" rel="nofollow">https://learn.microsoft.com/en-us/powershell/module/psreadli...</a>) and it works great.<p>As someone who works mostly in WSL and has to use PS occasionally, it really reduces the overhead of the context switch.
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
A much larger base for ksh (as a pdksh descendent) is Android. OpenBSD is a tiny community in comparison, although Android has acquired code directly from OpenBSD, notably the C library.<p>The vi editing mode is always present in ksh, but is optional in dash. If present, the POSIX standard requires that "set -o vi" enable this mode, although other methods to enable it are not prohibited (such as inputrc for bash/readline), and as such is a "universal trick."<p>The article is relying on some Emacs mode, which is not POSIX.<p>$_ is not POSIX if I remember correctly.<p>History in vi mode is easier, just escape, then forward slash (or question mark) and the search term (regex?), then either "n" or "N" to search the direction or its reverse.<p>I've seen a lot of people who don't like vi mode, but its presence is the most deeply standardized.
Ctrl-r works well at searching character trigrams, which can include space. Trigrams without space work well with auto_resume=substring .<p>`| sudo tee file` when current user does not have permission to >file
> The “Works (Almost) Everywhere” Club<p>> The Backspace Replacements<p>Also known as "emacs editing mode". Funnily enough, what POSIX mandates is the support for "vi editing mode" which, to my knowledge, almost nobody ever uses. But it's there in most shells, and you can enable it with "set -o vi" in e.g. bash.
And if you set `set editing-mode vi` in ~/.inputrc (readline configuration) you'll have it in even more places.
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.<p>Once you get used to it, it is painful to go back.
Guilty as charged
Something that should be mentioned is starting a command with a space doesn't add it to your history in most shells, really useful for one-off commands that you don't want cluttering your history.<p>Also, increase your `$HISTSIZE` to more than you think you would need, there have been cases where it helped me find some obscure command I ran like 3 years before.
Never heard of instant truncate, nor `fc`, nor `Esc .`<p>Quite a few useful ones
My favourite shell trick is to comment my code:<p><pre><code> $ some_long_command -with -args -easily -forgotten # thatspecialthing
</code></pre>
... Some weeks later ..<p><pre><code> $ CTRL-R<specialthing>
</code></pre>
.. finds:<p><pre><code> $ some_long_command -with -args -easily -forgotten # thatspecialthing
</code></pre>
Need to see all the special things you've done this week/whenever?<p><pre><code> $ history | grep "\#"
</code></pre>
...<p>Makes for a definite return of sanity ..
I just open, agent in tui, and ask it to do what I want and make a plan, i read the plan edit it and run it.<p>Simple, no need to learn any commandline these days.<p>I used to use arch and all, and managed many big projects. I find little value in learning new tools anymore, just feed it docs and it generated working plan most of the time<p>Now I've moved to coding in Haskell, which i find suits me better than wasting my time with cli and exploring what options all these cli tools have.
What I hate is that if you start a command with a space it is not recorded in the history. This happens often when copy+pasting commands. I know you can turn it off but still ... this drives me mad.