Comment by alberto-m

12 hours ago

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.

    • What I love about the default Bash Crtl-C behaviour is that once a command has been located, the bash history is moved to the history of that command, until Enter is pressed.

        $ a
        bash: a: command not found
        $ b
        bash: b: command not found
        $ c
        bash: c: command not found
        $ d
        bash: d: command not found
        $ <CTRL-R> b <UP>
        $ a
      

      That's great if I don't remember which command I was experimenting with, but I do know other commands that I did around that time (usually a file that I edited with VIM).

    • Looking at it from a "law of least surprise" angle, it's exactly how it should behave.

      "I typed 'cd di↑' and you're giving me 'pwd'??"

  • If you use multiple terminals it kinda sucks unless you do export PROMPT_COMMAND='history -a' in your.bashrc or something cause only the last closed terminal saves to history

  • export EDITOR=vi and then hitting Esc puts you into vi mode; k, j to move up/down through history or pressing / to search etc including using regex is all available.

I agree it's a game changer! For bash to do the same I put this in my .inputrc:

    ## arrow up
    "\e[A":history-search-backward
    ## arrow down
    "\e[B":history-search-forward

This is the default `fish` shell behavior. Type anything, up/down keys to iterate through full commands that containing the term; alt + up/down to iterate through args containing the term.

I do something similar. I leave up and down arrows alone, but have ctrl+p and ctrl+n behave as you describe.

Heh. I've done this since forever, but I use PgUp and PgDn so I can retain the original meaning of the up arrow key.

Did this many years ago (but with bash) -- life changing is an apt way of saying it.

  • Here's the Bash commands for this in case anyone is looking for them

      bind '"\e[A"':history-search-backward
      bind '"\e[B"':history-search-forward

> life-changing

For further life-changing experience... add aliases to .bash_aliases

    alias gph='history | grep --colour -i '
    alias gpc='grep --colour -Hin '
    #if gnu time is installed
    alias timef='/usr/bin/time -f "tm %E , cpu %P , mem %M" '

  • I've got many like these I copied from various people over the years.

    One I came up and that I use all the time:

        alias wl='wc -l'
    

    I use it so much I sometimes forget it's not stock.

That's a nice one.

One thing I do is configure my keyboard so that "modifier+{ijkl}" mimicks the inverted T arrows key cluster. So there's never a need for me to reach for the arrow keys. And {ijk} makes more sense than vi's {hjkl} and is faster/more logical/less key fingers travel. The nice thing is: as I do this at the keyboard level, this works in every single map. "modifier" in my case is "an easily reachable key in a natural hand position on which my left thumb is always resting" but YMMV.

I set that up years ago and it works in every app: it's gorgeous. Heck, I'm using it while editing this very message for example.

And of course it composes with SHIFT too: it's basically arrow keys, except at the fingers' natural positions.