Bash One-Liners Explained, Part V: Navigating around
catonmat.net
catonmat.net
$ set -o vi This command changes the key bindings to vi's. If vi's your favorite editor, you'll love this. I'll cover the vi mode in more details in the next part of the article.
I'd love to find a cheat sheet for vi bash usage (and also an indicator for which editing mode I'm in).
Luckily, zsh actually allows you to change your prompt when the mode changes. I have mine set up to change the color of part of it whenever I'm in command mode. Definitely worth setting up.
This has made me even happier than learning I could get vim key bindings in vim's own command-line mode[1]. Thanks again!
[1](C-f from command-line mode, or q: from normal)
In zsh, you can type: "bindkey" to get a listing. IIRC, in bash it is "bind -p".
"\e[B": history-search-forward
"\e[A": history-search-backward
And this to your .bash_proflie export HISTCONTROL=erasedups
export HISTSIZE=100000
shopt -s histappend
Now the up/down arrow keys auto search and complete backwards/forwards based on what's written. If the line is empty, it behaves as normal.This is also pretty neat, in your .bash_proflie:
bind '"\t":menu-complete'
Enables cyclic tab completionThese are the first things I do when I'm on another terminal.
Any other tips? These two were brilliant!
I've been using the remap of the up/down arrow for a while too, and it is crazily useful indeed. It's the first thing I do on a new terminal. That, together with adjusting PS1 and setting up my common aliases.
> When this variable is assigned a value, the history file is truncated
Which I read as meaning if you export the following then you should get infinite entries:
export HISTFILESIZE=
I'm testing to see if it works for this also: export HISTSIZE=To go to the previous space, Ctrl+R SPACE works for me.
Been using Emacs for a year and I didn't know this. O_o
In OSX you can set it up in keyboard preferences and in Windows I use Autohotkey.
Working on a keyboard with a regular Caps Lock key feels very strange after all this time.
In iTerm [2] I have the left alt/option key setup as meta, so things like meta-b are much easier to type then Esc-b.
[1] "You'll often see Meta+b but there is no such key on the keyboards anymore." [2] Profiles -> Keys "Left option acts as meta"
One shortcut that used often is Ctrl-o. When you have a few commands in your history that you want to repeat in that seqeunce, search for the first command in the group, optionally edit it if you want, and press Ctrl-o instead of the ENTER key.
After this command is executed, the next command in the history is presented to you. Press Ctrl-o again to continue the sequence, or press ENTER once you reached the last command in the sequence.
If you want skip a command in the sequence, instead of Ctrl-o just press Ctrl-n (or down-arrow) to get the next one in sequence.
Control-q: push-line-or-edit -- this saves the current command without executing it, allows you to run another command, then puts back the saved command for you to edit/run.
Esc-A: accept-and-hold -- execute command and maintain cursor position, so you can edit command and re-run.
Esc-' : quote-line -- escapes the single quotes in a line.
Old Vim user here, who has used emacs mode since moving from ksh to bash for about 8-10 years. Recently, switched back to vi mode, however, I have mapped Ctrl-A, Ctrl-E and a few more so i can use them in vi mode too. e.g.
bindkey "^A" beginning-of-linehttp://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html#...
edit:
oh, this is the first time I've seen this: there is a vi mode for bash http://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html#...