I have some fairly useful replacements.
These are definitions and commands for comments. Some C/C++ style, CSS (c multi-line), python style, and batch. They also come in multi line (where applicable), single line, and consecutive single line (good for code folding).
What is nice about these, is that they seem to work pretty good with folding without collapsing the next line into the first line. They seem to be working pretty good for me.
"batch_comments": {
"find": "((?:^)?^\\S\\r\\n]*)(::^\\r\\n]*)",
"replace": "",
"scope_filter": "comment", "-string"]
},
"batch_consecutive_single_comments": {
"find": "((?:^\\S\\r\\n]*::^\\r\\n]*(?:\\r\\n])?)*)(^\\S\\r\\n]*::^\\r\\n]*)",
"replace": "",
"scope_filter": "comment", "-string"]
},
"c_comments": {
"find": "((?:^)?^\\S\\r\\n]*)(//^\\r\\n]*)",
"replace": "",
"scope_filter": "comment", "-string"]
},
"c_consecutive_single_comments": {
"find": "((?:^\\S\\r\\n]*//^\\r\\n]*(?:\\r\\n])?)*)(^\\S\\r\\n]*//^\\r\\n]*)",
"replace": "",
"scope_filter": "comment", "-string"]
},
"c_multi_line_comments": {
"find": "((?:^)?^\\S\\r\\n]*)/(\\*(\\w\\W]*?)\\*/)(^\\S\\r\\n]*)",
"replace": " ",
"scope_filter": "comment", "-string"]
},
"python_comments": {
"find": "((?:^)?^\\S\\r\\n]*)(#^\\r\\n]*)",
"replace": "",
"scope_filter": "comment", "-string"]
},
"python_consecutive_single_comments": {
"find": "((?:^\\S\\r\\n]*#^\\r\\n]*(?:\\r\\n])?)*)(^\\S\\r\\n]*#^\\r\\n]*)",
"replace": "",
"scope_filter": "comment", "-!string"]
},
"python_multi_line_double_block_strings": {
"find": "((?:^)?^\\S\\r\\n]*)(\"\"\"(\\w\\W]*?)\"\"\")(^\\S\\r\\n]*)",
"replace": " ",
"scope_filter": "-comment", "string.quoted.double.block.python"]
},
"python_multi_line_single_block_strings": {
"find": "((?:^)?^\\S\\r\\n]*)('''(\\w\\W]*?)''')(^\\S\\r\\n]*)",
"replace": " ",
"scope_filter": "-comment", "string.quoted.single.block.python"]
}
Here are some remove and folding commands for comments.
{
"caption": "Remove: Python Style Comments",
"command": "reg_replace",
"args": {"replacements": "python_comments", "remove_trailing_spaces"], "find_only": true}
},
{
"caption": "Remove: Python Block Strings",
"command": "reg_replace",
"args": {"replacements":
"python_multi_line_double_block_strings",
"python_multi_line_single_block_strings",
"remove_trailing_spaces"
], "find_only": true}
},
{
"caption": "Remove: C Style Comments",
"command": "reg_replace",
"args": {"replacements": "c_comments", "c_multi_line_comments", "remove_trailing_spaces"], "find_only": true}
},
{
"caption": "Remove: CSS Comments",
"command": "reg_replace",
"args": {"replacements": "c_multi_line_comments", "remove_trailing_spaces"], "find_only": true}
},
{
"caption": "Remove: Batch Comments",
"command": "reg_replace",
"args": {"replacements": "batch_comments", "batch_multi_line_comments", "remove_trailing_spaces"], "find_only": true}
},
// Fold Comments
{
"caption": "Code Folding: Fold Python Style Comments",
"command": "reg_replace",
"args": {"replacements": "python_consecutive_single_comments"], "action": "fold"}
},
{
"caption": "Code Folding: Fold Python Block Strings",
"command": "reg_replace",
"args": {"replacements":
"python_multi_line_double_block_strings",
"python_multi_line_single_block_strings"
], "action": "fold"}
},
{
"caption": "Code Folding: Fold C Style Comments",
"command": "reg_replace",
"args": {"replacements": "c_consecutive_single_comments", "c_multi_line_comments"], "action": "fold"}
},
{
"caption": "Code Folding: Fold CSS Comments",
"command": "reg_replace",
"args": {"replacements": "c_multi_line_comments"], "action": "fold"}
},
{
"caption": "Code Folding: Fold Batch Comments",
"command": "reg_replace",
"args": {"replacements": "batch_consecutive_single_comments", "batch_multi_line_comments"], "action": "fold"}
}
Unfold commands would be the same as the fold, except you change the caption to say “unfold” and change the action to “unfold”.
If you have any improvements, let me know. If you know of some other comment styles, let me know. I may add some of these definitions by default to the plugin; I will have to see.
**Edit: ** Typo fixed on Python block strings.
**Edit: ** Scope fix on all comments