Sunday, September 18, 2011

Re: Remembering syntax when moving in and out of buffers

On Mon, 19 Sep 2011, Tony Mechelynck wrote:

> On 19/09/11 00:14, Benjamin R. Haskell wrote:
>> = What [the OP was] doing: =
>>
>> 1. in your .vimrc (1 line):
>>
>> autocmd BufReadPost,BufNewFile *.myfile source ~/myfile.vim
>>
>> 2. in ~/myfile.vim (6 lines of code):
>>
>> if exists("b:myfile")
>> finish
>> endif
>>
>> let b:myfile = 1
>> syntax match special /special/
>> highlight special term=bold cterm=bold
>>
>>
>> = What [the OP] could be doing (one version): =
>>
>> 1. in your .vimrc (3 lines):
>
> these 3 lines actually belong in ~/.vim/filetype.vim (for Unix) or in
> ~/vimfiles/filetype.vim (for Windows) or in $VIM/vimfiles/filetype.vim
> (for access by any user, on any OS) — in all cases, create missing
> directories as you go along. The "other version" below (replacing
> filetype.vim by ftdetect/myfile.vim and doing away with the augroup,
> which Vim sets before sourcing everything in the ftdetect directory)
> would also work.

Interesting. I didn't know about ~/.vim/filetype.vim.


> This way this autocommand will be correctly forgotten and remembered
> back if ever you do ":filetype off" and later ":filetype on".
>
> See ":help new-filetype".

This wasn't the version I was advocating. But, since the OP implied
that creating the proper directories was more complex ("Thanks but if
these are the alternatives then it's simpler to just [keep things as
before]"), I was providing a way that would work without having to
create more directories.

For the record, my suggested "= What you could be doing (the other
version): =" is the one I actually recommend (and is what new-filetype
seems to advocate):


>> = What you could be doing (the other version): =
>>
>> 1. in ~/.vim/ftdetect/myfile.vim (1 line):
>>
>> au BufReadPost,BufNewFile *.myfile setf myfile
>>
>> 2. put the last two lines of ~/myfile.vim into ~/.vim/syntax/myfile.vim
>> (2 lines):
>>
>> syn match special /special/
>> hi special term=bold cterm=bold

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

No comments:

Post a Comment