Is there a way to remove all comment lines in Sublime Text 3?

I know that in Vim you can delete all comments in a file using the keyboard shortcut, but I could not find a similar method in ST3. This would be especially useful for gemfiles and other files that distract comments around the world.

Search for keyboard shortcuts or quick and easy alternatives.

Any suggestions?

+6
source share
2 answers

The simplest is to use a search and replace regular expression, for example,

  • Cmd - Opt - f
  • Select an option . * (Regular expression)
  • Find what: ^#.*\n Note 1
  • Replace with: (nothing)

This will not work for comment blocks. For them you need to be a little more complicated, (very) roughly:

 =begin(.|\n)*=end 

(not verified safely.)

If you do this a lot (which IMO is a little strange), you can bind it to a key.


Note 1: This works for comments at the beginning of lines. It does not add comments to lines of code; if you want to handle this, you can remove ^ , but you will need something about EOLs that will disappear during replacement. Or you can just ignore EOL and have some empty lines where there were line comments.

+9
source

What Dave answered didn't help me. So do the following if itโ€™s the same for you,

To remove an all specific <tag> element that contains content inside it:

  • Ctrl + H (on PC)
  • Enable (regular expression):. * Or Alt + R
  • Find what:

    RE syntax for working with a specific tag

    (? s) <start tag>. *? <end tag>

    For example, for CSS comment tags

    (? WITH)/*.*?*/

    For HTML comment tags,

    & l (s?) ;! -. * โ†’

  • Replace: leave the field blank

  • Replace all
+3
source

Source: https://habr.com/ru/post/974840/


All Articles