← Back to context

Comment by alberto-m

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