It is a bit complicated, but doable. Like the bash command:
bind '"(" "\Cv()\e[D"' bind '"\"" "\Cv\"\Cv\"\e[D"'
As a parameter in .inputrc (so any program using readline gets the behavior):
"(": "\Cv()\e[D" "\"": "\Cv\"\Cv\"\e[D"
You can prefix each key with Control-v to enter “simple” quotes and left parentheses without triggering automatic closure.
The above implies Emacs bindings. For vi bindings use
bind '"(": "\Cv()\ei"' bind '"\"" "\Cv\"\Cv\"\ei"'
or
"(": "\Cv()\ei" "\"": "\Cv\"\Cv\"\ei"
Essentially, just replace [D with i ; instead of sending an escape sequence to move the cursor to the left, just send \e to return to command mode after inserting the brackets / quotes, then re-enter the insert mode, which should place the cursor inside the characters just entered.
chepner Jul 26 2018-12-12T00: 00Z
source share