Saturday, December 6, 2014

Re: How to highlight keyword in comments?

Hi Shiyao!

On Fr, 05 Dez 2014, Shiyao Ma wrote:

> My objective: to highlight all my custom keywords within comments regardless of the filetype.
>
> Sympton: everything works fine (in Python, Cpp, etc). But in .tex file, the highlight won't work.
>
> My code:
> augroup colors_settings
> autocmd!
> autocmd Syntax * syn keyword globalTodo contained XXX TODO NB FIXME WARN
> \ | exe "syn match globalComment +" . substitute(escape(&cms, ' ."*+'), '\s*%s', '.*', ""). "+ contains=globalTodo"
> \ | hi link globalTodo Todo
> \ | hi link globalComment Comment
> augroup END
>
>
> Example tex file:
>
> % NB here it will be highlighed.
> \documentclass[conference]{IEEEtran}
>
> \begin{document}
> \title{Network Security Through Penetration}
> \maketitle
>
> % NB here won't be higlighed.
> \begin{abstract}\boldmath
> \end{abstract}
>
> \section{Conclusion}
>
> \end{document}
>
>
> The code is self contained, so it's easy to try out locally. The first NB is higlighted while the second is not.
>
> How to highlight the second?
>
> In case of gmail 72tw limit, a bpaste version: https://bpaste.net/show/5a1f372a98d8

I am not exactly sure, why Vim doesn't highlight the second comment. But
here is a way to make what you want. Create a file
~/.vim/after/syntax/tex.vim
and insert there:

syn keyword globalTodo contained XXX TODO NB FIXME WARN
syn cluster texCommentGroup add=globalTodo
hi link globalTodo Todo

That should be it. By modifying the texCommentGroup cluster, you can add
more syntax items to all comment sections in your file.

See also the help add :h mysyntaxfile-add


Best,
Christian
--
Das Leben besteht in dem, was ein Mensch den ganzen Tag über denkt.
-- Ralph Waldo Emerson

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: