Why is TODO always highlighted in vim? - vim

I was going through a bash file and I noticed that TODO was written twice in the file, and both the instances were highlighted. Why's this? Is it because TODOs are very significant and might avert wastage of time for developers? What's the history behind this?

This is just a syntax element which may be defined (or not) for this particular buffer.
Typically syntax is defined in $VIMRUNTIME/syntax/[filetype].vim. The relevant command could look like this, for example:
syn keyword cTodo contained TODO FIXME XXX
Whether such definition is useful or not is subjective, I admit.
You can see all syntax elements defined for the current buffer with :syntax command.

Related

vim highlighting: remove syntax keyword

One of the vim plugins I use does:
syn keyword rustTodo contained TODO FIXME XXX NB NOTE
Resulting in highlighting NB in comments, which I don't like. Is there a way to either redefine the keywords or remove one from them? Looking at :help syn-keyword makes me think that this is not possible.
If that is the only definition for rustTodo (these are cummulative), you can remove and then redefine it:
syn clear rustTodo
syn keyword rustTodo contained TODO FIXME XXX NOTE
Unfortunately, the granularity for removal of syntax items is limited to whole syntax groups (here : rustTodo); you cannot pick individual keywords unless they also have separate groups (which would result in much more linking of highlight groups and therefore inefficient).
To make this permanent, put it into ~/.vim/after/syntax/rust.vim
If you think that the majority of users doesn't like NB here, please suggest to the author to drop it. Adding it back as a personal customization is easier and more maintainable than removing it...
I had a similar question while importing syntax files from within other syntax files, and came up with a dirty hack.
Instead of loading your syntax file with
syn include #othersyntax syntax/othersyntax.vim
you can use
syn include #othersyntax !sed 's/<NB>//' syntax/othersyntax.vim
Eww. This brings serious platform dependency and security issues, but at least relieves you of the burden to keep the replacement keyword list in sync with upstream.

What does the comment "COMBAK" mean?

I was looking at the vimscript syntax file in the syntax directory, and under the keyword vimTodo were the words COMBAK, FIXME, TODO, and XXX. I can figure out what FIXME and TODO mean pretty easily, and I can guess what some might use XXX for, but I have no idea what COMBAK is for.
It must have a meaning of some sort, else there would be no reason to highlight it. I get that it's a code tag, but what does it mean? My best guess so far is an abbreviation for COMEBACK, though I doubt this.
Here is what I found so far:
Googling it got me nothing of use, and a google code search for COMBAK (with or without the quotes) got 0 results. I eventually Googled codetag "COMBAK" and found a single result, which uses it as a tag in a comment twice (a [ctrl+F] will find it): http://pastebin.com/H6mjbyBh.
The program is written in Vimscript, and contains both a vimscript syntax file and vimscript indent plugin file for lisp, along with some other massive functions.
Yes, it literally means "COME BACK".

removing spell syntax highlighting in vim

This question is a sequel question of this one. I have the following script that removes capitalized words from vim spell check.
syn match myExCapitalWords +\<\w*[A-Z]\K*\>+ contains=#NoSpell
But it works only if I do syn clear first. But then all other highlighting (e.g. markdown) gets lost. I went through syn list to see what might be causing the conflict, but now I am out of clue.
It looks like you're extending arbitrary syntaxes with your myExCapitalWords group. Whether / in which syntax items that works depends on the underlying syntax. Unfortunately, it is not possible to extend arbitrary syntaxes in a blanket way. That's why you're seeing problems that can only be solved via :syn clear (which gets rid of the underlying syntax).
A syntax contains multiple groups, some of which are usually contained= in others. If you introduce a new syntax, it will only apply to where no other syntax group already matches. You can force your group into others via containedin=TOP or even containedin=ALL, but that overlay may prevent other original groups from matching, and causes strange effects because their own contains= or nextgroup= now don't apply.
So, unfortunately, there's no general solution for this. If you're only interested in a few syntaxes, you can tweak your one-liner to make it cooperate with the underlying syntax (e.g. try containedin={syntaxName}Comment{s}), but there's no generally applicable solution.

How to add words to vim coloring in C/C++ mode?

I notice that in C/C++ mode, comments such as TODO XXX and FIXME get special color marking.
How can I add the word HACK to this list of words to be marked in the same way?
I tried adding the following to my ~/.vimrc, but it didn't work:
syn keyword cTodo contained TODO FIXME XXX HACK
I would advise against directly modifying the original syntax file; you then have to maintain your version whenever the original changes (e.g. after a Vim upgrade). For these small syntax enhancements, the place is in the ~/.vim/after/syntax/c.vim file, which is sourced after the original syntax. The line would be
syn keyword cTodo contained HACK
You need to modify the syntax file. Typically, it is in /usr/share/vim/vim72/syntax, and the file you want is c.vim and cpp.vim. You will see a line syn keyword cTodo contained followed by a list of words that are considered under the Todo label for coloring. You can add your word there, or make your own keyword, but adding your own keyword would mean adding your keyword to the coloring file as well.
For user only changes, make a directory ~/.vim/syntax. Copy the c.vim and cpp.vim files there, and edit as necessary.
Second edit: Decided to look further, and it appears you can just add to a current syntax file, but I haven't tried it. Add your one line you added to your .vimrc to a file in ~/.vim/after/syntax

Context sensitive word wrap in vi/vim

How can I can specific word wrapping for specific tags. For example, in LaTex I want word wrapping for my paragraphs but not for my figure commands (they are always very long and run off the screen).
Or with Javascript, I want the right margin for code to be at, for example 50 columns, but for the comments to be at only 40 columns
This is not builtin
You could probably script something yourself using a devious combination of `formatexpr` and synID(). I suggest you look at the help of the latter first, because it contains inspirational samples:
for id in synstack(line("."), col("."))
echo synIDattr(id, "name")
endfor
taken from :he synstack
The formatexpr is usually set to something like
:set formatexpr=mylang#Format()
thus delegating to a filetype plugin. You could implement the function to use different margins for different syntax contexts.
Bear in mind
the default formatexpr (if absent, formatprg) are probably no good for a source file (in my experience it has the tendency to string together lines as if they were text paragraphs). But then again, you can implement it any which way you want
that syntax highlighting may become out of sync. I'm not sure what happens when the cursor is at, say, 70% of a large document and you issue ggVGgq. It might not update the syntax highlighting all the way (meaning that your formatexpr function would get the 'wrong' synID() values. You get around this by saying something like
:syntax sync fromstart
this again might impact the highlighting performance depending on the size/complexity of the source and highlighting scripts

Resources