Sublime text TODO and others highlighting

364 Views Asked by At

I'm looking for a way to highlight TODOs and TODO-like in Sublime text.

I tried Linter and SublimeLinter-annotations but I cannot find a way or a clear documentation to better highlight the TODO line.

I put this in the SublimeLinter.sublime-settings:

// SublimeLinter Settings - User
{
    // "debug": true,
    
    "linters": {
        "annotations": {
            "infos": ["TODO"],
            "warnings": ["WARNING"],
            "errors": ["ERROR"],
            "mark_message": true,
        },
    }
}

with this result:

linter

More on large files, for me, this highlight isn't clearly visible.

How to?

  • set the foreground and background colors of the whole comment line
  • highlight also multi-line comments like /* TODO ... \n ... */

Other than TODOs, I need to highlight also // TEST and // INFO comments with different colors.

I already tried SublimeTODO but it highlights also nested comments.

2

There are 2 best solutions below

1
Harsh Panchal On

You can try with new custom .tmTheme color scheme file:

  • Example for TODO inside CustomColorScheme.tmTheme:
<dict>
    <key>name</key>
    <string>TODO</string>
    <key>scope</key>
    <string>annotation.todo</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#FF0000</string>
        <key>background</key>
        <string>#FFFF00</string>
    </dict>
</dict>

Then add the custom scheme path to the default settings file or user-specific settings file located at SublimeLinter.sublime-settings

{
    "color_scheme": "Packages/CustomColorScheme/CustomColorScheme.tmTheme"
}

Reference Link

2
Yauheni Leaniuk On
  1. Create ToDoColor.sublime-syntax in your Sublime User directory (In my case Win10: C:\Users\[Username]\AppData\Roaming\Sublime Text\Packages\User)

  2. Paste there something like that (I created this one for my todo list):

    %YAML 1.2
    
    ---
    name: ToDoColor
    file_extensions: [ todo ] # you can add your extension/s here
    scope: source.MyScopeName
    
    contexts:
      main:
        - match: '\b(TODO|todo)\b'
          scope: entity.name.class
        - match: '\b(DONE|done)\b'
          scope: string
        - match: '\b(PENDING|pending)\b'
          scope: entity.name.function
        - match: '\b(DROP|drop)\b'
          scope: entity.name.tag
        - match: '#.*'
          scope: comment.line
    
  3. Next create file with provided above extension (.todo in my case)

  4. View - Syntax - ToDoColor

  5. You should see something like this for this text:

    TODO or todo
    DONE or done
    PENDING or pending
    DROP or drop
    # Commented line
    

enter image description here

FYI: Of course you can add your words/regexes and I used build-in colors here

So for your specific case you can insert this part before comment sign:

- match: '(#.*?\b)(TODO|todo)(.*)'
  captures:
      1: comment.line
      2: entity.name.class.todo
      3: comment.line

enter image description here