Assuming your shell is bash and you use emacs editing mode (set -o emacs
), this answers your question for parenthesis and double quotes.
To explain what is going on there, here's one that works for {}
:
bind '"{" "\C-v{}\e[D"'
Let's take a walk through the interior of the '
. In the first pair of "
we have:
{
This is pretty simple, it just means to replace a left curly brace with the following stuff.
The second pair of "
starts off with:
\C-v{}
Here we insert the open and close brace. We need both because we're replacing what was originally typed, not appending to it. The \C-v
is a Control-v character, which stands for a verbatim insert (brief history of terminal keys). This allows us to insert the {
without triggering this binding again. Finally, we have:
\e[D
This is just the escape code for the left arrow key, so it moves the cursor to between the braces.