A few useful standard readline bindings
One day, I'm not sure exactly when, I stumbled over the standard
M-. for 'yank-last-arg'. The description you can find
in your local readline manpage may be a little abstract, so here's
the simplified version:
M-. inserts whatever was the last word
on the previous command line into your current command line.
Did you perhaps type:
$ ls *some*[Cc]omplex*pattern
and now you want to grep through files matching that pattern? Easy;
grep thing M-.' and you'll wind up with '
(You can also use
M-_, according to the manpage.)
This turns out to not be the only potentially useful standard readline binding that I wasn't aware of, so here's my current little collection.
M-C-yis 'yank first argument'. With an argument, both it and
M-.are 'yank nth argument', but I'm not sure I'd ever do that instead of some form of line editing.
(Providing numeric arguments is a bit awkward in readline and we're into the same 'counting words' problem territory that I have with Vi. It's mentally easier to reshape a command line than count out that I want the third, fourth, and sixth argument.)
C-x C-uis incremental undo.
M-rreverts the line to its original state. This is probably mostly useful if I've accidentally modified a line in the history buffer and want to discard those changes to revert it to its pristine as-originally-typed state.
In Bash specifically (although not necessarily other things that use readline), you can force certain completions regardless of bad attempts to be clever. These are:
M-/for filename completion
M-!for command name completion
M-$for variable name completion
M-@for hostname completion
M-~for user name completion
C-x <char> versions that list all the possible
completions. The keys for these are reasonably related to what
you're forcing a completion for, so I have at least some chance of
remembering them in the future.
(There are probably other readline bindings that are useful, and
for that matter you can rebind things with a
users of readline probably do all sorts of things there, especially
with conditional constructs and variables and so on.)