Line Comment position
-
hi Community,
Is there an option to place the line comments at the first column instead of placing before the first character.
Eg: The below needs to be achieved.// TEST This is expected comment
The below is what is happening.
// TEST This is actual comment
Any setting to achieve, placing the comment chars at the very beginning of the line?
Regards,
-
Hello oirfeodent oirfeodent,
I don’t think that there a native option to do so. But it’s very easy to get it, with a simple regex !
For instance, if we consider the comment characters, used in languages C, C#, C++ ( and some others ! ) :
-
Open the Find/Replace dialog ( CTRL + H )
-
Check the Wrap around option
-
Select the Regular expression search mode
-
SEARCH =
^( +)(//|/\*|\*/)
-
REPLACE =
\2\1
-
Click on the Replade All button
Voilà !
So, if we start this the C text, below :
/* Here is a way to move the comments at the very beginning of a line */ // Final test
after the S/R, we get the C text, below :
/* Here is a way to move the comments at the very beginning of a line */ // Final test
Notes :
This regex is quite simple. Just note that :
-
The space characters and the comment character, enclosed in round brackets, are stored, respectively, at groups 1 and 2
-
In group 2, the star meta-character needs to be escaped, as
\*
, in order to be taken literally -
In replacement, the two groups are, simply, swapped !
IMPORTANT :
If your text contains leading tabulations, instead of spaces, this regex will, unfortunately, modify the original indentation of the comment text. Just because the physical length of a tabulation character depends, of course, on its location, in a line
To avoid this behaviour, if you don’t mind, you may, previously, change all the tabulation characters by space characters
with the N++ option Edit - Blank operations - TAB to SpaceBest Regards,
guy038
-
-
I think the OP is referring to the
Ctrl+Q
and/orCtrl+K
line-(un-)comment shortcuts. -
Hi guy038 & MAPJe71,
Thx for your response. I was referring to line (un)comment shortcuts.
If they are not available natively, can I submit a patch?https://github.com/notepad-plus-plus/notepad-plus-plus/pull/2394
The above pull request is added, is there any thing else required for submitting pull requests?
I am new to this forum, let me know if I have missed something.Reagrds,