Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

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

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

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."

Download and install TODO Highlight extension. After you download and install the extension, make sure you restart your VSCode. Now please follow the following steps in order to add custom keyword highlighting in your code.

  • On windows hold down Ctrl + Shift and on mac Command + Shift, thenthe key press p.

    a command line opens up.

  • On the command line type "open settings" and click on "Preferences: open settings".

    Settings window will open.

  • under the "search setting" input on the right handside look for the three dots "..." and click on it.

  • Click on "Open settings.json".

    "User Settings" tab will open. It contains a split screen window. on the left side you see the defualt settings and on the right side you see the user settings

  • in the "search settings" type "todohighlight.keywords"

    you will see "todohighlight.keywords": [].

  • Hover over it with your mouse

    a little pen will show up on its left side

  • click on it

    you'll see a drop-down select menu opens.

  • click on "Replace in settings".

you can now see "todohighlight.keywords": [] in the right pannel window (USER SETTINGS).

This is an array that contains json objects such as following:

"todohighlight.keywords": [
    {
        "text": "NOTE:",
        "color": "#000000",
        "backgroundColor": "#ff00dc",
        "overviewRulerColor": "grey"
    },
    {
        "text": "your choice of keyword",
        "color": "your choice of color",
        "backgroundColor": "your choice of color",
        "overviewRulerColor": "your choice of color"
    }
]

if you're not familiar with json notation copy the content of "todohighligh.keywords" from the sample above and past it to your "user settings" window in between the two [] brackets. you can change the values on the left side of : colon in between "" double quotes. if you would like to add more than two keywords simply add a comma after the last closing curly bracket } in your "user settings" and copy/past one json object (which is from one { open bracket to the first closing } bracket) and then change its content. you can add as many keywords as you'd like to.

MAKE SURE YOU SAVE THE FILE by holding down Ctrl(windows) / command(mac) and press the key "s" or from the menu bar go to File -> Save

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top