문제

In vim, whenever I add a comment like this

int somevar = 100; //XXX Some Comment Here

The "XXX" part of my comment gets automatically highlighted. "TODO" in a comment also gets highlighted similarly. I've used these myself quite widely to mark todos/draw attention, but never bothered to learn what makes "XXX" and "TODO" special. What makes these two words special?

Are there are other special words in comments that automatically get highlighted?

도움이 되었습니까?

해결책 2

These are made special by syntax files that Vim relies on to style various items within a source code.

For example on my machine, following default syntax file for C, (which is sourced by C++ syntax file too), contains the line

file: /Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/c.vim

syn keyword     cTodo           contained TODO FIXME XXX

Color and styling for cTodo, if you search would be defined within c.vim file.

For C++ the file name is cpp.vim, which sources (includes) c.vim

Why these keywords?
We'll I didn't research much, but programmers started to put attention catching prefixes to their comments, so that they (or someone else) can come to that area of code later (for whatever reason, as stated in the comment). Editors, like Vim, noticed this and added syntax highlighting for these prefixes to make them stand-out even more.

For that matter, most of the editors today have editable (or customizable) syntax highlighting. You can add your own keywords that you want highlighted in comments! (for other keywords/tokens too).

다른 팁

  • TODO to indicate planned enhancements.
  • XXX to warn other programmers of problematic or misguiding code.

Source.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top