3

I am kinda using Notepad++ very active, and I am a big fan of hotkeys. I usually use CTRL + Q for toggling line comments, but it always bothers me that the comment character(s) are indented like the lines itself, and do not start at the beginning of the line.

Simple example. That's what Notepad++ does by default:

# root = {
    # set_stuff = flag
    # modify_base = new_modifier
# }

What I want is:

# root = {
#   set_stuff = flag
#   modify_base = new_modifier
# }

Is that possible via a hotkey?
(I don't want to always select all lines at the start via ALT + LeftClick and enter the line comment signs manually)

2
  • Your question is a little vague in its details. Are you after a shortcut key that simply adds a # as first character to the line the cursor is on? or does it also have to work with a selection?
    – LPChip
    Dec 9 '16 at 22:36
  • @LPChip It should work with selection, and also single lines. I mean, exactly the behavior than CTRL + Q has, but just adding the comment sign at the beginning of the line, not somewhere in the middle.
    – Wolfsblvt
    Dec 9 '16 at 23:03
3

I just tested a way of doing this that seems to work...

  • You can select a piece of text
  • Go to Macro -> "start recording"
  • Go to search -> replace
    • Select "in selection" and "regular expression"
    • Find: (.*) Replace with: # \1
    • select Replace all
  • Go to Macro -> "stop recording"
  • Now save the macro, and assign any shortcut key you like
5
  • Of course... this will only add #, not toggle... Making the macro more elaborate might work...
    – Wouter
    Dec 14 '16 at 8:40
  • This might be a solution to script a more advanced solution: nppscripts.codeplex.com/documentation
    – Wouter
    Dec 14 '16 at 8:45
  • 1
    That's.... something. I con't really need it to remove the comment as well, CTRL+Q does already a fine job removing comments at the beginning of the line. So I could just make it a different hotkey. Maybe even CTRL+K and replace the default "add line comments". I will test a bit around with it, then may make this the solution. Thank you!
    – Wolfsblvt
    Dec 14 '16 at 14:26
  • 1
    Used the regex ^, so that it only mathes start of the line. Sadly it doesn't work if a line is only partly selected (like CTRL+Q does), but I guess that's an issue I could live with.
    – Wolfsblvt
    Dec 14 '16 at 14:32
  • If you search for this: (\r?\n?)(.*) and replace with this: \1# \2 It seems to work. Not sure if I'm overlooking any pitfalls though....
    – Wouter
    Dec 15 '16 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.