Commenting code in Notepad++
Solution 1
CTRL+Q Block comment/uncomment.
See Keyboard And Mouse Shortcuts - Notepad++ Wiki.
Solution 2
Try the following shortcut:
Ctrl+K.
Solution 3
This link was exactly what I was searching for .
Let me summarize the answers for others' benefit (for python and notepad++)
1) Ctrl+K on multiple lines (i.e. selected region) allows you to block comment.
Also note that pressing the combination multiple times allows you to add multiple "#"s (sometimes I use that while testing to differentiate from other comments)
2) Ctrl+Shift+K (on the commented region) allows you to perform block uncomment
3) Ctrl+Shift+K on an uncommented selected region does not comment it
4) Ctrl+Q allows you to block comment/uncomment in a toggled mode (meaning, you cannot add multiple '#'s like in 1) )
Hope this helps another wandering soul.
Question - how would you develop a hack of keyboard combinations to comment/uncomment if there were no shortcuts? Just curious. I've no clue hence asking.
Solution 4
Yes in Notepad++ you can do that!
Some hotkeys regarding comments:
- Ctrl+Q Toggle block comment
- Ctrl+K Block comment
- Ctrl+Shift+K Block uncomment
- Ctrl+Shift+Q Stream comment
Source: shortcutworld.com from the Comment / uncomment section.
On the link you will find many other useful shortcuts too.
Solution 5
for .sql files Ctrl+K or Ctrl+Q does not work.
to insert comments in .sql files in Notepad++ try Ctrl+Shift+Q
(there is no shortcut to uncomment the code block though. I have tried that on v5.8.2 )
Related videos on Youtube
Arnkrishn
Updated on February 24, 2022Comments
-
Arnkrishn about 2 years
I'm using Notepad++ as an editor to write programs in Python. It might sound daft but I looked around in the editor and could not find any means (not the manual way but something like in Emacs) to do a block comment in my code.
Since so many language settings are supported in Notepad++, I'm curious to find a way to block comment code.
-
toto almost 15 yearsBoth CTRL-K and CTRL-Q can be seen in the Edit menu of Notepad++
-
user1066101 almost 15 years"comment sections of my code"? In Python? The "#" key is missing? Clearly, you're not talking about Python comments using "#" or docstrings. What are you talking about?
-
Arnkrishn almost 15 yearsActually, I wanted to block comment my code written in Python or in fact any other language, in Notepad++ editor. May be that was not quite clear from my question. But Niels's and other answers helped.
-
user1066101 almost 15 yearsAre you talking about applying comments to all lines of a block of code? Please update the question -- don't comment on your own question when you can fix the question.
-
Daniel Shields almost 15 yearsIs there a shortcut to comment out the current line of code? Ctrl-K and Ctrl-Q both need selected characters to work.
-
Martyn Davis over 9 years@ReadySquid - Notepad++ version 6.6.8 does not require any selection for Ctrl-K or Ctrl-Q to work (Introduced sometime in the last 5 years)
-
Pacerier almost 9 years@toto, It's not shown. Which version are you using?
-
-
vicsz about 13 yearsTo Get Ctrl-K and Ctrl-Q working for SQL you need to edit the langs.xml file in the Notepad++ directory. (With Admin rights, and with notepad++ closed). Add commentLine="--" to the language settings for SQL.
-
machineaddict over 10 yearsCTRL+Q is line comment, for block comment the shortcut is CTRL+SHIFT+Q
-
BillyNair about 9 yearsFrom dev.mysql.com - From a “-- ” sequence to the end of the line. In MySQL, the “-- ” (double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on). This syntax differs slightly from standard SQL comment syntax. So, see if you need to use "-- ", but Notepad++ will change the color either way
-
Shashank Sawant about 9 years
Hope this helps another wandering soul.
It does. -
Pacerier almost 9 years@machineaddict, What's the opposite of that?
-
Pacerier almost 9 years@BillyNair, Wow, good catch! Notepad++'s invalid highlighting is going to cause some serious bugs.
-
machineaddict almost 9 yearsI've seen you are searching for this keyboard shortcut in multiple posts on SE websites. I don't know the shortcut. I only use Ctrl-Q combinations for comments.
-
Juha Untinen about 8 yearsNote that in order for it to work, you MUST specify the (programming) Language for the code. Also, if you copypaste a piece of code to a new file without specifying the language manually - or - it contains a mix of languages (eg. inline SQL in Python code), the block comment/uncomment will not work.
-
Friso Horstman over 7 yearsI laughed at first because i entered ctrl+w (thinking i actually hit ctrl+q(uit) like the answer proposed). but yeah, ctrl+q will actually comment multiple lines in notepad++ whereas netbeans uses ctrl + shift + w to comment multiple lines.
-
vladasimovic almost 7 yearsFor comment press Ctrl+Q or Ctrl + Shift + Q or Ctrl+K. For uncomment press Ctrl+Shift+K.
-
walen over 2 yearsUpvoted as this is the first answer to correctly mention that Ctrl+Shift+Q turns the whole selection into ONE comment instead of commenting each line separately.
-
root about 2 years@walen What difference do you mean? For me, Ctrl+Shift+Q and Ctrl+K have the same effect. What does "stream comment" mean?
-
walen about 2 years@root Comment using one
/*
at the beggining of the block and one*/
at the end of it, instead of one//
on each line which is what Ctrl+K does (for me and user3898160 at least). -
root about 2 years@walen Got it, thanks. Depending on the programming language, Ctrl+Shift+Q and Ctrl+K may or may not have the same effect.