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 am looking for the command line shortcut to comment out the current line in the terminal.

For example, I might enter git commit -am "a comm and then realize I don't actually want to commit yet. I'd press the key combination and my half entered line would be commented out and entered, thus saving it into history, but not actually executing.

Anyone know this keyboard shortcut?

share|improve this question
up vote 8 down vote accepted

Documented in the bash manual here:

M-# or AltShift3

share|improve this answer
I never new this. Thanks for sharing. – jaychris Sep 6 '13 at 1:13
Note that M-# and <Alt>+<#> are usually the same. <Alt>+<Shift>+<3> is the way to achieve this on an American keyboard. So this combination is only valid on keyboards where <Shift>+<3> translates to #. – Tim Sep 6 '13 at 7:53
Glenn Jackman: You have an ability to repeatedly show me stuff that I find interesting, but did not know of. I have learned several things from you on this site, which is a big motivation for being here at all, so: thank you :-) – Daniel Andersson Sep 6 '13 at 11:22

Home # Enter works obviously, and is quite short. An alternative to Home is Ctrl+A.

Another possibility that might be closer to what you want in practice is to clear the line with Ctrl+U, which stores it in a buffer which you can recall with Ctrl+Y within the same terminal session. This won't save it to history, but from your use case it sounds like you want it within the same terminal session anyway.

share|improve this answer

You must log in to answer this question.

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