Reputation: 189
I am using Sublime Text 3. I have encountered a problem. I don't know how to toggle XML line comment.
I know there is a Toggle Comment
function in Sublime Text 3 and I tried. However, the result is not the same as what I envisioned.
For example, I want to toggle comment the following XML code:
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
I want to make it like this(Just like Eclipse's line comment):
<!-- <profile> -->
<!-- <id>jdk-1.8</id> -->
<!-- <activation> -->
<!-- <activeByDefault>true</activeByDefault> -->
<!-- <jdk>1.8</jdk> -->
<!-- </activation> -->
<!-- <properties> -->
<!-- <maven.compiler.source>1.8</maven.compiler.source> -->
<!-- <maven.compiler.target>1.8</maven.compiler.target> -->
<!-- <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> -->
<!-- </properties> -->
<!-- </profile> -->
However by using Toggle Comment
in Sublime, I can only get the following code:
<!-- <profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile> -->
I don't know how to achieve this goal. I search this problem on Google but I can not find any useful information. Can you give me some suggestions?
Upvotes: 2
Views: 1988
Reputation: 1
Author's Note: This started out a simple remark. One dusk passed and one dawn approaching, the memory of what that simplicity might have involved has escaped to wherever all the orphaned thoughts go.
(I'll learn this RWML (ReallyWeird Markup Language) for real some day!)
This URL has some stuff that is spot-on with this.. I'm sorry I'm not in the frame of mind nor do I have ample time to hash out a better post on this..
For Starters: Check this out .
APPETIZER:
**
**
The contributes.languages Contribution Point allows you to define a language configuration that controls the following Declarative Language Features:
VS Code offers two commands for comment toggling. Toggle Line Comment and Toggle Block Comment. You can specify comments.blockComment and comments.lineComment to control how VS Code should comment out lines / blocks.
{
"comments": {
"lineComment": "//",
"blockComment": ["/*", "*/"]
}
}
When you move the cursor to a bracket defined here, VS Code will highlight that bracket together with its matching pair.
{
"brackets": [["{", "}"], ["[", "]"], ["(", ")"]]
}
That should pretty much clarify the view from the white line, drilling down to implement a comprehensive re-write scenario that anticipates and resolves multi-language demand complications; extending the reach of programming capabilities, combative problem-solving, and community approval highs. _____
/* """
_
. _ dB SiGN - Db _
. _ dB SEAL - Db _
. _ dB LiVR - Db _
. -::.::::. .::-
. -,__________.-'_______
-<C>:-------::---
----][)<<<
. . . (O) . . . . .(O) . . . . . .
;,__., . ___ . ___ . ___ . ___ . _ . __ . _ ___,;"
+||| : aA Bb cC Dd eE Ff gG Hh iI Jj kK Ll mM |
++|| : Nn oO Pp qQ Rr sS Tt uU Vv wW Xx yY ZzZ |
+++| : 00 01 02 10 11 12 20 21 22 03 31 23 33 |
.+| : A♈ T♉ G♊ C♋ L♌ V♍🔆 L♎ S♏ S♐ C♑ A♒ P♓ |
...| - - - - - - - - |
,=-__________________________________________.;|,._
""" */
Left/(Carnival_Act) = {
"by "&"j.l.richman (a.k.a., psidre densum
Felix, tehGlitchGHOST
"&" "&"\&\n"&
"Kroah - Prophet of the Borneless)"}
Best viewed !btfo
Upvotes: -1
Reputation: 22791
In general, Sublime can be configured to know the difference between a line and block comment and act accordingly. However as far as I can tell, this can't be done for XML because it needs to wrap the content with comment characters.
More specifically, the configuration options for comments specify either a TM_COMMENT_START for a pure line comment or TM_COMMENT_START and TM_COMMENT_END for a block comment. If both are present, the toggle command selects the correct one based on content and context.
For XML, it uses a pair due to how comments in XML works, which means that only block comments are possible. However, when you invoke the command with no selection, it assumes that the selection wraps the entire line. If you have a selection, that's what gets wrapped.
One way around this problem is to split your selection into lines before you toggle the comment. You can do that via Selection > Split into Lines
from the menu (this will also show you what your key binding is for this command).
It is possible to group these commands into a macro so that you don't have to take multiple steps on your own.
Such a macro could look like the following (saved in your User
package as XML_Line_Comment.sublime-macro
):
[
{
"command": "split_selection_into_lines"
},
{
"command": "toggle_comment",
"args": {"block": false}
},
{
"command": "single_selection"
},
{
"command": "move_to",
"args": {"extend": false, "to": "bol" }
}
]
This would split the selection, toggle the comment, and then return to a single selection (and jump to the start of the line). You can modify this as appropriate (e.g. if you don't want to revert to single selection afterwards).
You can run this macro from the menu bar (Tools > Macros > User > XML_Line_Comment
), but a better way might be to set up a key binding. An example of that would be:
{
"keys": ["ctrl+/"],
"command": "run_macro_file",
"args": { "file": "res://Packages/User/XML_Line_Comment.sublime-macro" },
"context": [
{ "key": "selection_empty", "operator": "equal", "operand": false},
{ "key": "selector", "operator": "equal", "operand": "text.xml"},
]
},
This will cause the key that normally toggles comments to run your macro for the specific case of there being a selection while you're in an XML file.
Upvotes: 2