If I do a M-! to run a shell command, usually any output will appear in a new, temporary buffer. But sometimes, seemingly at random, the output will instead be inserted directly into the active buffer. If this happens and I run the same command over again, it normally works as expected the second time.

Is this just me? Why might this be happening, and how do I prevent it?

  • 1
    That's what happens if you hit C-u, or C- or M- with a digit or minus sign, before M-!. Might that be what's going on?
    – legoscia
    Mar 16, 2015 at 13:37

1 Answer 1


If you give M-! a prefix argument, any prefix argument, it will insert the output at the point.

C-h c <key> will tell you exactly which function is being run when you press a key. In this case, it's shell-command. You can read the documentation by typing C-h f shell-command RET:

Execute string COMMAND in inferior shell; display output, if any. With prefix argument, insert the COMMAND's output at point.

You can also use C-h k to combine the above two help commands. That is, C-h k M-! will open the help window for the command that M-! runs, whatever it may be.

  • Ah... well then I guess I must be accidentally touching some additional key sometimes, which is interpreted as an argument. I'll view-lossage next time it happens to confirm.
    – Brian Z
    Mar 16, 2015 at 14:34
  • 1
    @BrianZ, good idea. If the issue persists, there are some variables (prefix-arg, current-prefix-arg) that possibly might be getting set erroneously by some rogue package. Though this probably isn't very likely. I'm much more inclined to blame accidental key presses as you suggest (see Ockham's Razor).
    – nanny
    Mar 16, 2015 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.