Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to permanently save a keyboard macro that I've recorded using C-x ( and C-x ). Is there an easy way to "see the source" for my newly recorded macro so that I can bind it to a keyboard shortcut in ~/.inputrc?

I thought dump-macros would do it, but it doesn't seem to...

share|improve this question
Well, I'll be damned. I didn't know about this feature. – Charlie Martin Jun 11 '11 at 0:53
I use gnome-terminal and gconf-editor for configuring keyboard shortcuts. – saeedgnu Jun 11 '11 at 12:39

Best I could think of is to try:

echo >>.inputrc '<ctrl-x e>'

Or if the macro has multiple lines try:

echo >>.inputrc <<EOF
<ctrl-x e>

If you have used control characters you may wish to put a sed in there to replace them with the right escape codes for inputrc.

Then go in and edit the last line to have the right prefix and suffix for what you are trying to achieve ...

share|improve this answer
save a step, edit .inputrc, position to wherever you want the macro and C-x e to 'type it in'. But yeah, I'd say this is the best way, of course, you can put it anywhere you want, it's just a bunch of keystrokes. If you're not in the 'right mode/place/program', you'll likely get misunderstood inputs. But one would expect that if you didn't use the macro in the right place, right? – lornix Sep 18 '11 at 22:08
up vote 1 down vote accepted

Turns out it's really not possible, that is, it wasn't possible until tonight!

Since I was curious to dig into the bash source code anyways I went ahead and added this feature :). We'll see if the bash maintainers apply my patch.

share|improve this answer

Add this line to .inputrc:

alias macro
share|improve this answer
oh, thanks for correcting that, my bad :/ – FALL3N Jun 26 '11 at 20:45

It appears that .inputrc allows you to just edit your commands in. I tried using dump-macros also but couldn't get it to work nor is there much documentation about it. Perhaps it doesn't work or is deprecated.

If there was a command like xev for emacs bindings, that would be helpful. In any case, I think your best bet is to edit inputrc using the guidelines in the first link below at the bottom of the page. It's quite easy to do.

The second link is an example inputrc file for help figuring out how to set up macros.

As an aside, there is also a cool command called bind -P which will list all of your macros.

Here's an example inputrc file:

share|improve this answer
Yeah, the whole point is to not have to write the macro by hand, but instead print out the one I just recorded... – mgalgs Jun 21 '11 at 4:06
turns out dump-macros simply prints out what your currently defined macros would output. – mgalgs Oct 14 '11 at 8:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .