Community
    • Login

    Line Comment position

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 3.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • oirfeodent oirfeodentO
      oirfeodent oirfeodent
      last edited by

      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,

      1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by guy038

        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 Space

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 0
        • MAPJe71M
          MAPJe71
          last edited by

          I think the OP is referring to the Ctrl+Q and/or Ctrl+K line-(un-)comment shortcuts.

          1 Reply Last reply Reply Quote 0
          • oirfeodent oirfeodentO
            oirfeodent oirfeodent
            last edited by

            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,

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors