Is there a way to delete all comments in a file using Notepad++?

后端 未结 9 2059
清歌不尽
清歌不尽 2020-12-13 04:40

Notepad++ obviously recognizes all comments as such. Is there a way to simply delete all?

Edit: Stat-R\'s bookmark method has helped greatly, not on

相关标签:
9条回答
  • 2020-12-13 05:13

    To remove Powershell comments if someone find it handy:

    Removing Comment in a Powershell using Notepad ++ To find just lines beginning with # (and not with # elsewhere in the line).

    1. Notepad++ SEARCH Menu > Find
    2. ‘Mark‘ Tab – fill in as below.
    3. Select ‘Mark All’ (clear all marks if used previously).

    Regex ^[#}

    enter image description here

    1. SEARCH Menu > bookmark > Remove (or do anything on the list with them)
    2. Clear all marks to reset

    You can select no comments just code by doing the following:

    Regex ^[^#}

    enter image description here

    0 讨论(0)
  • 2020-12-13 05:26

    Anton Largiader's answer was the most reliable one, including complex inline comments.

    However, it will leave many empty lines, including ones with empty characters (space, tabs...) so I would just add another step to make it almost perfect:

    After running the macro, just do:

    Edit > Line Operations > Remove Empty Lines

    OR

    Edit > Line Operations > Remove Empty Lines (Containing Blank Characters)

    1st option is good if you wish to remove only really empty lines 2nd options will remove every empty line even containing space etc. so there will be no more actual spacing left between code blocks. 1st option might be the safest with some manual cleanup afterwards.

    0 讨论(0)
  • 2020-12-13 05:28

    I have had some luck running a macro for the above. Basically:

    • search for // (F3)
    • select to end of line (shift+end)
    • delete (delete)

    Put // into the search dialog by just searching for it once. Then record the three steps in a macro, then play it back until EOF.

    The first time I did it I had a problem, but then it worked, not sure what I did differently.

    0 讨论(0)
  • 2020-12-13 05:29

    For a general file, first of all you need to know the comment operator of the language you are writing the file in. For example, in java script the comment operator is //. For the following code...

    enter image description here

    In NP++, you need to

    Mark the lines that contains '//'. Make sure the bookmark option is enabled.

    enter image description here

    Then, choose from NP++ menu Search>Bookmark>Remove Bookmarked lines

    enter image description here


    EDIT: Another solution after @Chris Mirno 's suggestion is as follows: Use regular expression. See the image below. It is self explanatory enter image description here

    To understand it better, refer to these

    0 讨论(0)
  • 2020-12-13 05:32

    Enter ctrl+shift+K to remove comment

    0 讨论(0)
  • 2020-12-13 05:36

    As someone suggested in another post, the simplest and most reliable is maybe to export the all text in .RTF format using Menu Plugin-->NppExport-->Export to RTF and then:

    -Open the newly created file in Word

    -Select any part of any comment

    -On the top-right side of Word clic Select--> Select all texts with similar formatting

    -Remove the selected comments all at once (del or cut if doesn't work)

    0 讨论(0)
提交回复
热议问题