How to highlight words which correspond to tags in a custom tag file ?

61 views
Skip to first unread message

tjg

unread,
Oct 14, 2012, 1:29:54 PM10/14/12
to v...@vim.org
Suppose I have a agenda file, in which I note things to do, e.g. :
2012.10.13 write to Inc
2012.10.14 write to Gmbh
etc...

I want to complement this file with incremented information about these
companies (quotes, articles, etc…).

So, I create a tag file : .vim/doc/vimlog.txt, in which I have both *Inc*
and *Gmbh*.
(NB :I have verified that I have, too, .vim/doc/tags)

Two tags are easy to remember, but a hundred ?

It would be handy to see immediately through highlighting (in magenta, to
take an example) - while writing the name of one of those companies - if I
already have information about it in my custom tag file, which would be then
a Ctrl-] away.

Is this achievable ?



--
View this message in context: http://vim.1045645.n5.nabble.com/How-to-highlight-words-which-correspond-to-tags-in-a-custom-tag-file-tp5711259.html
Sent from the Vim - General mailing list archive at Nabble.com.

Ben Fritz

unread,
Oct 15, 2012, 11:59:23 AM10/15/12
to vim...@googlegroups.com, v...@vim.org
On Sunday, October 14, 2012 12:30:50 PM UTC-5, tjg wrote:
> Suppose I have a agenda file, in which I note things to do, e.g. :
>
> 2012.10.13 write to Inc
>
> 2012.10.14 write to Gmbh
>
> etc...
>
>
>
> I want to complement this file with incremented information about these
>
> companies (quotes, articles, etc…).
>
>
>
> So, I create a tag file : .vim/doc/vimlog.txt, in which I have both *Inc*
>
> and *Gmbh*.
>
> (NB :I have verified that I have, too, .vim/doc/tags)
>
>
>
> Two tags are easy to remember, but a hundred ?
>
>
>
> It would be handy to see immediately through highlighting (in magenta, to
>
> take an example) - while writing the name of one of those companies - if I
>
> already have information about it in my custom tag file, which would be then
>
> a Ctrl-] away.
>
>
>
> Is this achievable ?
>
>
>
>
>

Maybe you can get it working with one of these:

http://www.vim.org/scripts/script.php?script_id=3114
http://www.vim.org/scripts/script.php?script_id=2646

They both use ctags though so I'm not certain it's workable.

You could also parse the vimlog.txt file in vimscript and make a :syn keyword or :syn match rule for each word found.

tjg

unread,
Oct 15, 2012, 1:02:38 PM10/15/12
to v...@vim.org
Thank you for your answer.

I would rather not use plugins, and anyway, ctags is most certainly overkill
for me, because I only write plain text (on Terminal Vim in my MBpro ... and
on an Android smartphone with VimTouch).

Your second suggestion brings other - naïve - questions :

- Where is the vimlog.txt file ? Must I create it ?
- Is it impossible to parse the .vim/doc/tags file for *keywords* through a
function ?

Thanks again




--
View this message in context: http://vim.1045645.n5.nabble.com/How-to-highlight-words-which-correspond-to-tags-in-a-custom-tag-file-tp5711259p5711280.html

Ben Fritz

unread,
Oct 15, 2012, 4:24:31 PM10/15/12
to vim...@googlegroups.com, v...@vim.org
On Monday, October 15, 2012 12:03:30 PM UTC-5, tjg wrote:
>
> I would rather not use plugins, and anyway, ctags is most certainly overkill
> for me, because I only write plain text (on Terminal Vim in my MBpro ... and
> on an Android smartphone with VimTouch).
>
>

You're going to need a plugin of some sort here, even if you must write it yourself. Vim doesn't do syntax highlighting of any kind without one, and certainly not syntax highlighting of a configurable dictionary of words. The plugin could be a very lightweight syntax file only if you want, but you'll need one.

>
> Your second suggestion brings other - naïve - questions :
>
> - Where is the vimlog.txt file ? Must I create it ?
>

You created it already. You told us in your original post:

> So, I create a tag file : .vim/doc/vimlog.txt, in which I have both *Inc*
> and *Gmbh*.
> (NB :I have verified that I have, too, .vim/doc/tags)

> - Is it impossible to parse the .vim/doc/tags file for *keywords* through a
> function ?
>

You can get all tags Vim knows about which match a regular expression using the taglist() function. Or you can use readfile() to read in the contents of a file and parse it line by line in whatever way you wish.

You could also make a static syntax file with your desired keywords.

Or, if your keywords are set off from normal text in some way, with special tokens or something, make a syntax file to highlight them based on the special tokens.

tjg

unread,
Oct 16, 2012, 3:29:51 AM10/16/12
to v...@vim.org
First of all, sorry for my blunder about vimlog.txt. As you may have guessed,
this was an invented name , and I still had in mind the real name of my file
(vimnotes.txt)

I shall follow your different suggestions (I learn Vim the slow way...)

Again, thank you very much.



--
View this message in context: http://vim.1045645.n5.nabble.com/How-to-highlight-words-which-correspond-to-tags-in-a-custom-tag-file-tp5711259p5711292.html
Reply all
Reply to author
Forward
0 new messages