4

I have shift-tab bound to shell-expand-line in my .inputrc. However, I want shift-tab to also insert a space character after doing the shell-expand-line. How can I do this?

This is what my .inputrc currently looks like:

"^[[Z": shell-expand-line

The ^[[Z is what shift-tab looks like. I've tried the following possibilities, but they don't work:

"^[[Z": "shell-expand-line "
"^[[Z": shell-expand-line " "
"^[[Z": shell-expand-line" "
xdavidliu
  • 343

1 Answers1

5

Bindings have to specify either a builtin command, or a text macro (a string that will be inserted), not a combination of the two. But the macro can contain another bound key sequence that does specify a command, plus any characters you want to insert. As shell-expand-line is already bound to C-M-e in bash, all you need is

"\e[Z": "\e\C-e "

If you wanted to use a command that didn't already have such a binding, you could create an intermediate binding, such as

"\C-\xff": shell-expand-line
"\e[Z": "\C-\xff "
JigglyNaga
  • 7,886
  • \C-E is \C-e -- in the terminal, there's no difference between ctrl and ctrl-shift. Better use \xff instead. –  Oct 25 '19 at 14:42
  • additionally for the particular case asked in the OP, there's no need for an intermediate key because shell-expand-line is by default C-M-e – xdavidliu Oct 25 '19 at 14:46
  • @pizdelect Thanks, I hadn't tested that properly. I made it \C-\xff as just \xff caused other side-effects. – JigglyNaga Oct 25 '19 at 14:54
  • @xdavidliu Good point, I didn't notice the default binding. I've added the one-line solution, but leaving the "intermediate" method as it's useful for the more general case. – JigglyNaga Oct 25 '19 at 14:55
  • for some reason "\C-\M-e " didn't work for me; I had to use "\e-^E ", where the ^E is a literal C-e character inserted using emacs... – xdavidliu Oct 25 '19 at 15:03
  • I try to avoid using literals in answers because copying them to clipboard tends to turn them into the component characters (^, E). What does bind -q shell-expand-line show for you? – JigglyNaga Oct 25 '19 at 15:07
  • for me, it shows shell-expand-line can be invoked via "\e\C-e". – xdavidliu Oct 26 '19 at 02:48