visual-studio 如何在 Visual Studio 中突出显示用户指定的单词?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/633258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:15:55  来源:igfitidea点击:

How to highlight user-specified words in Visual Studio?

visual-studiosyntax-highlighting

提问by Beep beep

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.

我的团队经常将 TODO 一词放在未完成的代码部分。有没有办法将用户指定的关键字添加到 Visual Studio,以便以某种方式突出显示这些关键字?例如,在 vim 中,TODO 一词会自动突出显示。

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

例如,我想看到这样的东西:

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

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

采纳答案by scott

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 notbe highlighted. That can be achieved with one of the available TODO highlighters.

这些令牌将添加到任务列表中,但不会突出显示。这可以通过可用的 TODO 荧光笔之一来实现。

回答by goku_da_master

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

正如其他人所说,您需要一个 VS 插件(从 VS 2015 开始)来突出显示文本。对于使用 Resharper 的用户:

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

从菜单转到 ReSharper->选项->工具->待办事项。

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

添加您的新评论和模式。您可以通过编辑来复制现有的。我使用了与Todo我的新评论相同的设置:

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

// AnyYouWant 此评论以蓝色突出显示

回答by Chris M

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

我认为您正在寻找自定义关键字突出显示:http: //msdn.microsoft.com/en-us/library/zy61y8b8%28VS.80%29.aspx

回答by i_am_jorf

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

Visual Studio通过托管包框架支持自定义语法突出显示

回答by Ash M

In Visual Studio:

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

在那里您可以添加任何用户指定的词,它会在您进行构建和查看任务列表的任何时候出现在您的任务列表中,与 //TODO: 出现的方式相同。

回答by DKroot

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.

如果您有 ReSharper(商业版),它将使用相同的颜色突出显示所有任务:字体和颜色 > ReSharper Todo Item。ReSharper 还会在垂直错误条上标记任务。

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

VS 2015 的 Remarker(免费):https://visualstudiogallery.msdn.microsoft.com/32af9cb5-bb6e-4f02-97c6-a172c3ac5445或 VS 2013:https://visualstudiogallery.msdn.microsoft.com/878f133 48a4-b1c4-85dfb7a269a9可以使用不同的样式突出显示不同的任务标记。

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

同样适用于 VS 2010-2013 的 VS10x Comments Extender(免费),2015 的私人测试版:https://visualstudiogallery.msdn.microsoft.com/17c68951-7743-40bd-ad35-608706f54a92

回答by Fnord

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

我发现并正在使用这个用于 VS 2010-2015 的可自定义注释突出显示扩展。

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

从它的描述中可以看出:“...您可以根据前景色格式化任务注释(TODO、HACK、UNDONE)。”