erkin
erkin

Reputation: 535

Is there a way to comment out a large chunk of code?

I'm trying to comment out a large piece of code in a program but it's too difficult to do it manually. Is there a program to do it for me? (making such program doesn't seem hard anyway) Also, I'm using emacs. Does emacs have such a function? (or an emacs Lisp file at least?)

Upvotes: 42

Views: 43851

Answers (5)

questionto42
questionto42

Reputation: 9552

Taking up two comments of the accepted answer, this is just another key binding on top of it:

For newcomers: hold Alt pressed and then press ;, this can comment and uncomment the selected region.

And also for newcomers: "it's worth reading the tutorial that comes with emacs for e.g. the description of the keyboard notation and basic commands."

Upvotes: 1

Mohanraj
Mohanraj

Reputation: 4210

The comment-region method bound to key M-;. You can select region using marker and then use M-; to comment/uncomment.

Upvotes: 36

Drew
Drew

Reputation: 30699

I bind comment-region to C-M-;. And remember that C-u uncomments the commented region.

E.g. C-u 2 C-M-; comments the region with ;; (in Lisp). Then C-u C-M-; uncomments the region. (The region must be active in both cases.)

Upvotes: 0

sawa
sawa

Reputation: 168101

You can mark at the beginning of the region that you want to comment out, move to the end of the region, then do C-c C-c or M-x comment-region.

Upvotes: 0

dfan
dfan

Reputation: 5824

In emacs, you can use M-x comment-region and M-x uncomment-region.

Upvotes: 70

Related Questions