在vim中,如何突出显示TODO:和FIXME :? [英] In vim, how do I highlight TODO: and FIXME:?

查看:379
本文介绍了在vim中,如何突出显示TODO:和FIXME :?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在vim中,突出显示了FIXME和TODO,但是我无法使FIXME:和TODO:(请注意关键字后的冒号)突出显示?我应该在我的.vimrc文件中放些什么来实现此目的?

In vim, FIXME and TODO are highlighted, but I can't get FIXME: and TODO: (note the colon after the keyword) to highlight? What should I put in my .vimrc to make this happen?

推荐答案

嗯,您已经发现问题了,但是这里是

Well, you've already found the problem, but here's the why.

语法匹配有三种基本类型:关键字,匹配项和区域。关键字是固定的字符串,通常用于基本语言关键字( int double 等)。您的情况,用于FIXME和TODO。我的意思确实是固定字符串。与匹配和区域(使用正则表达式)不同,它们必须是准确且完整的词。例如,从C语法开始:

There are three basic types of syntax matching: keywords, matches, and regions. Keywords are fixed strings, generally used for basic language keywords (int, double, ...) and also, in your case, for the FIXME and TODO. I really do mean fixed strings; they have to be exact and whole words, unlike matches and regions, which use regex. For example, from the C syntax:

syn keyword   cTodo   contained    TODO FIXME XXX

在几乎所有内置语法定义中,都使用类似的组名(cTodo)。

It looks like that in pretty much all built-in syntax definitions, just with different group names (cTodo).

iskeyword 告诉vim给定字符是否可以作为关键字的一部分。默认情况下,它不包含冒号,因此在查找关键字时,vim会将 FIXME:视为 FIXME,并忽略冒号。如果您在冒号( set iskeyword + =:)上加粗,现在可以定义额外的突出显示:

iskeyword tells vim whether a given character can be part of keyword. By default, it does not include colons, so when looking for keywords, vim sees "FIXME:" as "FIXME", and ignores the colon. If you tack on the colon (set iskeyword+=:), you can now define an extra bit of highlighting:

syn keyword   myTodo   contained   TODO: FIXME:

您如何将其工作到现有语法/突出显示组中。如果仅用于一种文件类型,则可以将其添加到该语法的todo组中(例如cTodo)。如果到处都需要它,可以按照我的建议执行 myTodo,然后将其直接链接到Todo高亮显示组()。

It's up to you how you want to work it into the existing syntax/highlight groups. If it's for just one filetype, you could add it to that syntax's todo group (e.g. cTodo). If you want it everywhere, you can do "myTodo" as I suggested, then link it straight to the Todo highlighting group (hi def link myTodo Todo).

或者,您可以单独保留 iskeyword (我可能会建议这样做),而只需使用匹配项:

Alternatively, you can leave iskeyword alone (I'd probably recommend this), and simply use a match:

syn match   myTodo   contained   "\<\(TODO\|FIXME\):"
hi def link myTodo Todo

这篇关于在vim中,如何突出显示TODO:和FIXME :?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆