Shortcuts to Move Faster in Bash Command Line(teohm.github.com)
teohm.github.com
Shortcuts to Move Faster in Bash Command Line
http://teohm.github.com/blog/2012/01/04/shortcuts-to-move-faster-in-bash-command-line/
25 comments
This is a description of the Emacs bindings, which are the default. Vi bindings are also available and can be enabled by adding
Peteris Krumins also has an article on bash command line editing with some extra information on completion:
http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-s...
set -o vi
to ~/.bashrc.Peteris Krumins also has an article on bash command line editing with some extra information on completion:
http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-s...
Beat me to it. (My first thought upon seeing the headline was, "wow, faster than vi mode?")
I haven't actually put the set into my .bashrc yet, I just end up typing it when I realize I'm about to navigate a lot.
I haven't actually put the set into my .bashrc yet, I just end up typing it when I realize I'm about to navigate a lot.
Semi-related, but what's the fastest vi way to get to the space right after the first word? For example, I might type
> ls /etc/foo/bar
and have my cursor at the end when I realize I want to type ls -l instead. I know there's got to be a faster way than what I'm currently doing, but I'm blanking.
(Yes, I know sometimes tacking on the command line switch at the end will work, but that's not true for all commands).
> ls /etc/foo/bar
and have my cursor at the end when I realize I want to type ls -l instead. I know there's got to be a faster way than what I'm currently doing, but I'm blanking.
(Yes, I know sometimes tacking on the command line switch at the end will work, but that's not true for all commands).
Shift-T (the opposite of up`t`o) and then `s`.
You can hit `;` if there are multiple incidences of 's'.
You can hit `;` if there are multiple incidences of 's'.
jj0W
that should work for commands without spaces in them.
I remap jj to escape so it is faster than moving my hand.
in ~/.inputrc
that should work for commands without spaces in them.
I remap jj to escape so it is faster than moving my hand.
in ~/.inputrc
set editing-mode vi
$if mode=vi
#normal mode
set keymap vi-insert
"jj": vi-movement-mode
$endifBash is out of place here actually, they are just general readline's and work in many places
http://cnswww.cns.cwru.edu/php/chet/readline/readline.html
http://cnswww.cns.cwru.edu/php/chet/readline/readline.html
My favorite tip is to stay in emacs mode, but whenever you have something "complicated" to do, use Ctrl-X Ctrl-E : it opens the current line in $EDITOR.
This is amazing. One of my persistent nuisances had been when and how to transition from command line to script. This makes it smooth!
Except all the line formatting gets lost in bash after executing the command; and it is automatically executed.
In zsh you still have the opportunity to inspect it once more when you leave the editor, and it maintains it's multiline format in the history.
In zsh you still have the opportunity to inspect it once more when you leave the editor, and it maintains it's multiline format in the history.
Also install the awesome autojump: https://github.com/joelthelion/autojump
If I was previously sitting in directory:
'/home/user/code/github.com/cookbooks/cassandra/recipes'
and I wanted to jump back to that dir from anywhere on the file system I could just type 'j cass rec' and it would autocomplete and jump to this location. Super helpful.
If I was previously sitting in directory:
'/home/user/code/github.com/cookbooks/cassandra/recipes'
and I wanted to jump back to that dir from anywhere on the file system I could just type 'j cass rec' and it would autocomplete and jump to this location. Super helpful.
Worth a mention is that you can customize how Readline handles these sorts of shortcuts in your ~/.inputrc file. For example, I use forward and backward by word far more often than by character, so I do this:
$if Bash
# various other stuff left out
# easier back and forth by word
"\C-b": backward-word
"\eb": backward-char
"\C-f": forward-word
"\ef": forward-char
$endif
For more examples and syntax, see http://docs.freebsd.org/info/readline/readline.info.Sample_I... and http://docs.freebsd.org/info/readline/readline.info.Readline....Note that you don't need to 'enable' the Meta key in Terminal on OS X.
By default, option does what it does in other programs, allowing you to type alternative characters. If you'd still like to keep that behaviour, you can send meta by pressing escape first -- Meta-b becomes escape, then b.
By default, option does what it does in other programs, allowing you to type alternative characters. If you'd still like to keep that behaviour, you can send meta by pressing escape first -- Meta-b becomes escape, then b.
$_ and !$ are additional ways to get the last argument of the previous command.
http://samrowe.com/wordpress/advancing-in-the-bash-shell/ is a good list of extra tips
http://samrowe.com/wordpress/advancing-in-the-bash-shell/ is a good list of extra tips
Very similar list here:
http://www.skorks.com/2009/09/bash-shortcuts-for-maximum-pro...
which includes some other nice shortcuts - like ctrl + xx
http://www.skorks.com/2009/09/bash-shortcuts-for-maximum-pro...
which includes some other nice shortcuts - like ctrl + xx
It's also worth noting that in OSX many of these shortcuts work anywhere you can enter text. I use ctrl+a/ctrl+e all the time.
What's wrong with using the arrow keys?
Is there a redo to go with undo?
Put the following in your ~/.inputrc
Now if you type, say:
You will cycle through commands in your history that start with the prefix "cat ".