Tuesday, November 10, 2015

Re: write a very basic syntax file

On 2015-11-10, Jose Caballero wrote:
> Hello,
>
> I am pretty sure this question has been already asked many times. I
> apologize if that is the case.
> I have been googling the topic for a while, and the problem is that I
> found too many different ways to [theoretically] do it, so I am not
> sure which one is the right one.
>
> So let's say I only want to highlight lines starting with char #
> (comments) in any file with extension .myfile
>
> I have vim 7.2
> I started by adding this line in my ~/.vimrc:
>
> au BufRead,BufNewFile *.myfile setfiletype myfile

It would be better, i.e., more likely to work as you expect, if you
instead put this line in ~/.vim/filetype.vim per the example in

:help new-filetype

Scroll down to part C.

> So I created directory ~/.vim/plugin/syntax/ and file
> ~/.vim/plugin/syntax/myfile.vim, with content
>
> if exists("b:current_syntax")
> finish
> endif
>
> echom "Our syntax highlighting code will go here."
>
> let b:current_syntax = "myfile"

This file should go into ~/.vim/syntax/, not ~/.vim/plugin/syntax/.
Plugin files under ~/.vim/ftplugin/, ~/.vim/syntax/ and
~/.vim/indent are sourced according to filetype when a file of a
particular type is opened. Plugin files under ~/.vim/plugin are all
opened whenever Vim starts.

> And here, to my surprise, now I see the message every time I open ANY
> file. So no worth it to keep moving on. I guess my first question is:
> where do I exactly set the filetype recognition, and where I should
> place the syntax file in such a way it does not mess with other
> filetypes?

HTH,
Gary

--
--
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:

Post a Comment