I need to comment out some blocks of code in Python. How can I do that with emacs? How can I prepend # character at the start of each line of a block?
The prepend() method inserts specified content at the beginning of the selected elements. Tip: To insert content at the end of the selected elements, use the append() method.
To prepend to a list in Python, use the list. insert() method with index set to 0, which adds an element at the beginning of the list.
To insert element as a first child using jQuery, use the prepend() method. The prepend( content ) method prepends content to the inside of every matched element.
To prepend an element to a linked list is to insert that element in front of the first element of the list. The prepended list element becomes the new head of the list. Program.
You can use the comment-region command using
M-x comment-region
Edit: And as suggested by @Gilles in comment you can use M-;
which according to the help is
Call the comment command you want (Do What I Mean).
If the region is active and 'transient-mark-mode' is on, call 'comment-region' (unless it only consists of comments, in which case it calls 'uncomment-region'). Else, if the current line is empty, call 'comment-insert-comment-function' if it is defined, otherwise insert a comment and indent it. Else if a prefix arg is specified, call 'comment-kill'. Else, call 'comment-indent'.
which is probably easier on the long run. :-) Remember that this is "mode-dependant", so you need to set python-mode before you comment using M-x python-mode
Or if you want to prefix every line with any type of character, select the text you want to comment and type
C-x r t
and type the character you want to prefix with. Remember that the caret must be on the first column on the last line that you select, or your text would be replaced.
You select text by pressing C-space and moving your caret around btw.
Here's a link that describes how to do this with arbitrary characters in rectangle mode.
This is handy because it only does this for the selected region of text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With