112

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.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
Arnkrishn
  • 29,828
  • 40
  • 114
  • 128
  • 12
    Both CTRL-K and CTRL-Q can be seen in the Edit menu of Notepad++ – toto Jun 20 '09 at 19:11
  • "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? – S.Lott Jun 20 '09 at 19:41
  • 2
    Actually, 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. – Arnkrishn Jun 20 '09 at 19:58
  • Are 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. – S.Lott Jun 20 '09 at 20:17
  • Is there a shortcut to comment out the current line of code? Ctrl-K and Ctrl-Q both need selected characters to work. – John Slavick Jun 21 '09 at 20:23
  • @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) – Martyn Davis Aug 07 '14 at 01:08
  • @toto, It's not shown. Which version are you using? – Pacerier Jun 30 '15 at 03:08

11 Answers11

151

CTRL+Q Block comment/uncomment.

See Keyboard And Mouse Shortcuts - Notepad++ Wiki.

Pang
  • 9,564
  • 146
  • 81
  • 122
Niels R.
  • 7,260
  • 5
  • 32
  • 44
  • 4
    CTRL+Q is line comment, for block comment the shortcut is CTRL+SHIFT+Q – machineaddict Nov 22 '13 at 08:43
  • 3
    @machineaddict, [What's the opposite](http://superuser.com/questions/790353/fastest-way-to-comment-out-multiple-lines-in-notepad/916881#comment1267743_790354) of that? – Pacerier Jun 30 '15 at 03:11
  • I'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. – machineaddict Jun 30 '15 at 07:11
  • 1
    Note 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*. – Juha Untinen Apr 22 '16 at 06:50
  • 1
    I 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. – Friso Horstman Sep 23 '16 at 22:20
  • For comment press Ctrl+Q or Ctrl + Shift + Q or Ctrl+K. For uncomment press Ctrl+Shift+K. – vladasimovic Jul 29 '17 at 19:24
  • The link is dead, and I didn't find an appropriate reference in the [user manual](https://npp-user-manual.org/docs/editing/ "Editing | Notepad++ User Manual"). For a compact overview, see for example [Notepad++ Cheat Sheet - Notepad++_Cheat_Sheet.pdf](http://www.cheat-sheets.org/saved-copy/Notepad++_Cheat_Sheet.pdf). – Wolf Jul 13 '23 at 08:46
27

Try the following shortcut:

Ctrl+K.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
Javier
  • 4,552
  • 7
  • 36
  • 46
25

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.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
Raaj
  • 1,180
  • 4
  • 18
  • 36
14

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.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
user3898160
  • 539
  • 4
  • 14
  • Upvoted 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. – walen Dec 02 '21 at 08:20
  • @walen What difference do you mean? For me, Ctrl+Shift+Q and Ctrl+K have the same effect. What does "stream comment" mean? – root May 02 '22 at 23:02
  • @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). – walen May 03 '22 at 08:09
  • @walen Got it, thanks. Depending on the programming language, Ctrl+Shift+Q and Ctrl+K may or may not have the same effect. – root May 03 '22 at 12:28
9

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 )

Hulk1991
  • 3,079
  • 13
  • 31
  • 46
N30
  • 3,463
  • 4
  • 34
  • 43
  • 7
    To 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. – vicsz Apr 21 '11 at 17:10
  • 1
    From [dev.mysql.com](http://dev.mysql.com/doc/refman/5.0/en/comments.html) - _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** – BillyNair Mar 04 '15 at 08:20
  • @BillyNair, Wow, good catch! Notepad++'s invalid highlighting is going to cause some serious bugs. – Pacerier Jun 30 '15 at 03:18
2

Use shortcut: Ctrl+Q. You can customize in Settings

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
user3402702
  • 91
  • 1
  • 11
1

In your n++ editor, you can go to Setting > Shortcut mapper and find all shortcut information as well as you can edit them :)

Md. Masudur Rahman
  • 1,028
  • 12
  • 30
1

Two ways for block commenting:

  1. Ctrl+Shift+Q

or

  1. Select the block
  2. Alt + Right click
  3. Choose block comment.
Fabrizio
  • 7,603
  • 6
  • 44
  • 104
Mahesh
  • 188
  • 2
  • 5
1

Without having selected a language type for your file there are no styles defined. Comment and block comment are language specific style preferences. If that's a PITA...

To select for multi-line editing you can use

shift + alt + down arrow

Kickaha
  • 3,680
  • 6
  • 38
  • 57
1

To add a comment under any code on NOTEPAD++ first we have to save and define the programming or scripting file type. Like, save the file as xml, html etc. Once the file is saved in proper format you will be able to add a comment directly using the shortcut ctrl+Q

Developer Guy
  • 2,318
  • 6
  • 19
  • 37
0

Just select the desired line and click on Ctrl + Q Ps: I am using Notepad++

Ikbel
  • 1,817
  • 1
  • 17
  • 30