Working on various GNU Readline-based CLIs and it would dramatically
speed me up if there was a way to have brackets and quotes
automatically closed when you type.
Thus typing a ' or ( on Bash (or other CLIs) would actually
append the closing quote or bracket '' or () and place the cursor
inbetween for writing.
I’ve looked around for quite some time trying to find out anything related
(e.g. ~/.inputrc setting), but didn’t find anything and I wonder if that’s
at all achievable. Any comments would be appreciated.
It’s a bit tricky, but doable. As a
bashcommand:As a setting in
.inputrc(so any program usingreadlinegets the behavior):You can prefix each key with Control-v to type “plain” quotes and left parentheses without triggering the auto-close behavior.
The above assumes Emacs keybindings. For vi bindings, use
or
Essentially, just replace the
[Dwithi; instead of sending the escape sequence to move the cursor left, just send\eto drop back into command mode after inserting the parentheses/quotes, then re-enter insert mode, which should position the cursor inside the characters just typed.