If I have a line like:

vec3 pos; // May not be defined.

And I want to shift the comment to a specific column number, say 27, such that I get:

vec3 pos; // May not be defined.

Is there a single command that can do this if I have the cursor placed just before the comment?

If not, what is the easiest way to achieve this affect?

I will be doing this regularly to keep comments aligned, so a quick and generic solution is best.

1 Answer 1


Set comment-column to whatever you want:

(setq comment-column 27)       ;it's 32 by default for javascript

Then M ; (bound to comment-dwim) will do it.

  • C-c ; isn't defined in my setup. What is the command name? Edit: Seems to be indent-for-comment. Please correct me if I am mistaken though. Commented Apr 9, 2017 at 3:25
  • Sorry - it should be M-; which is bound to comment-dwim - I don't know what I was thinking. I'll fix the answer.
    – NickD
    Commented Apr 9, 2017 at 3:31
  • Been using Emacs for almost 7 years and didn't know about this feature! X-D Thanks much. Commented Apr 9, 2017 at 3:37

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.