Beep beep
Beep beep

Reputation: 19181

How to highlight user-specified words in Visual Studio?

My team often puts the word TODO in unfinished sections of code. Is there a way to add user-specified keywords to Visual Studio so that these are highlighted in some way? For example, in vim the word TODO is automatically highlighted.

For example, I'd want to see something like this:

//This is a stub -TODO:move this to another project

Upvotes: 36

Views: 29590

Answers (9)

BaldManWithBeard
BaldManWithBeard

Reputation: 1

As others have answered, for those using ReSharper their tags should automatically be highlighted, but the place in the options to set tags is called "To-do Explorer". Unsure if it changed since the other answer but wanted to add that for any using ReSharper as of 2023.

Upvotes: 0

not2qubit
not2qubit

Reputation: 17077

There's a lot of them around, but the best and simplest one I've found is wayou.vscode-todo-highlight. However, it seem that the maintenance of this extension have been abandoned.

The settings is simple and clear to use, but unfortunately the example out-of-the-box settings (and documentation) sucks, so to make life simpler, just copy/paste this into your (User) setting JSON file.

On Win-10, the user settings is located here:
C:\Users\<username>\AppData\Roaming\Code\User\settings.json.

//------------------------------------------
// wayou.vscode-todo-highlight
//------------------------------------------
// For colors, see: 
// https://stackoverflow.com/questions/20541456/list-of-all-colors-available-for-powershell
"todohighlight.isEnable": true,
"todohighlight.isCaseSensitive": true,
"todohighlight.keywords": [
    "ToDo",
    "DEBUG:",
    "REVIEW:",
    {
        "text": "NOTE:",                                                // 
        "color": "yellow",                                              // 
        "backgroundColor": "#006400",                                   // DarkGreen #FF006400 (argb)
        "overviewRulerColor": "grey",                                   // 
        "fontWeight": "bold",                                           // 
    },
    {
        "text": "HACK:",                                                // 
        "color": "#000",                                                // 
        "isWholeLine": false,                                           // 
        "fontWeight": "bold",                                           // 
        //"margin":  "5px",                                             // [padding, border, margin] Not working!
    },
    {
        "text": "TODO:",                                                // 
        "color": "red",                                                 // 
        //"border": "1px solid red",                                    // 
        "borderRadius": "1px",                                          //NOTE: using borderRadius along with `border` or you will see nothing change
        "backgroundColor": "rgba(4,4,4,.2)",                            // "rgba(0,0,0,.2)"
        "isCaseSensitive": false,                                       // 
        // Add other styling properties here. 
    }
],
//"todohighlight.keywordsPattern": "TODO:|FIXME:|\\(([^)]+)\\)",        //highlight `TODO:`,`FIXME:` or content between parentheses
"todohighlight.defaultStyle": {
    "color": "red",                                                     // 
    "backgroundColor": "#ffab00",                                       // 
    "overviewRulerColor": "#ffab00",                                    // 
    "cursor": "pointer",                                                // 
    "border": "1px solid #666",                                         // 
    "borderRadius": "2px",                                              // 
    "isWholeLine": false,                                               // 
    // Add other default styling properties here. 
},
"todohighlight.include": [
    "**/*.js",
    "**/*.jsx",
    "**/*.ts",
    "**/*.tsx",
    "**/*.html",
    "**/*.php",
    "**/*.css",
    "**/*.scss",
    "**/*.ps1"
],
"todohighlight.exclude": [
    "**/node_modules/**",
    "**/bower_components/**",
    "**/dist/**",
    "**/build/**",
    "**/.vscode/**",
    "**/.github/**",
    "**/_output/**",
    "**/*.min.*",
    "**/*.map",
    "**/.next/**"
],
"todohighlight.maxFilesForSearch": 5120,
"todohighlight.toggleURI": false
//------------------------------------------

NOTE: I didn't enclose the outer {}s.

Upvotes: 0

scott
scott

Reputation: 746

In the Tools menu go to Options -> Environment -> Task List. Here you can enter Tokens.

These tokens will be added to the task list, but will not be highlighted. That can be achieved with one of the available TODO highlighters.

Upvotes: 20

i_am_jorf
i_am_jorf

Reputation: 54640

Visual Studio supports custom syntax highlighting through the Managed Package Framework.

Upvotes: 5

goku_da_master
goku_da_master

Reputation: 4317

As others have said, you need a plugin for VS (as of VS 2015 anyway) to highlight text. For those that are using Resharper:

From the menu go to ReSharper->Options->Tools->To-Do-Items.

Add your new comment and pattern. You can copy an existing one by editing it. I used the same settings as Todo for my new comment:

Title: AnythingYouWant

Regular Expression: `(?<=\W|^)(?<TAG>AnythingYouWant)(\W|$)(.*)`

Put a check "In comments"

Color: Web->Blue

Icon: Normal

And use it like this in your code:

// AnythingYouWant this comment is highlighted blue

Upvotes: 7

Dima Korobskiy
Dima Korobskiy

Reputation: 1556

Highlighting of task tokens is possible only via extensions.

If you have ReSharper (commercial), it would highlight all tasks using the same color: Fonts and Colors > ReSharper Todo Item. ReSharper also marks tasks on the vertical error stripe.

Remarker (free) for VS 2015: https://visualstudiogallery.msdn.microsoft.com/32af9cb5-bb6e-4f02-97c6-a172c3ac5445 or for VS 2013: https://visualstudiogallery.msdn.microsoft.com/87813da0-8f1c-48a4-b1c4-85dfb7a269a9 can highlight different task tokens using different styles.

Same goes for VS10x Comments Extender (free) for VS 2010-2013, private beta for 2015: https://visualstudiogallery.msdn.microsoft.com/17c68951-7743-40bd-ad35-608706f54a92

Upvotes: 3

Fnord
Fnord

Reputation: 11

I found and am using this customizable comment highlighting extension for VS 2010-2015.

From its description: "... you can format task comments (TODO, HACK, UNDONE) in terms of foreground color."

Upvotes: 1

Chris M
Chris M

Reputation: 59

I think you're looking for custom-defined keyword highlighting: http://msdn.microsoft.com/en-us/library/zy61y8b8%28VS.80%29.aspx

Upvotes: 5

Ash M
Ash M

Reputation: 1399

In Visual Studio:

Go to Tools > Options > Environment > Task list

There you can add any user=specified words, and it will appear in your task list any time you make a build and view the task list, in the same manner that //TODO: appears.

Upvotes: 3

Related Questions