Comment toggling
One key comments or uncomments the line or selection in the language's own syntax: //, #, <!-- -->, -- and the rest.
Comment out a line or a block with one key, in whatever language you are in, and press it again to bring the code back.
- One key for every language: Edit: Toggle Comment is
M-;in the Emacs keymap andCtrl+/in the other keymaps (Cmd+/on macOS). - The right syntax:
//and/* */in Java and C-like languages,#in Python, shell and YAML,<!-- -->in HTML, XML and Markdown,--in SQL, and so on. - Lines or blocks. A single line gets a line comment and a multi-line selection a block comment, or whichever form the language has.
- Tidy markers. Indentation is kept, and the markers of several lines line up in one column.
- Scripts stay runnable. A
#!shebang line is never commented, and a shell here-document is left alone unless you select the line that opens it. - Follows the file. In an INI file such as
setup.cfg, the comment character is the one the file uses.
See the Comments guide.