0

In my vim environment, I want to add a few specific snippets that should only be active when I am editing mySpecial.html file.

Since this file is an html file I want it to have the html filetype. But on the other hand, if I edit any other html file, I don't want the specific snippets to be active. So, it seems I cannot use the standard filetype mechanism for this.

Is there any solution to my problem?

René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293

3 Answers3

2

For the original (Michael Sanders) snipMate, I've defined the following command:

:command! -bar -nargs=1 -complete=filetype AddSnippets silent call ExtractSnipsFile(g:snippets_dir . <q-args> . '.snippets', &l:filetype)

With that, you can interactively or through an autocmd add the snippets:

:autocmd BufRead,BufNewFile mySpecial.html AddSnippets mySpecial
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
1

This sounds like an interesting feature request.

In the mean time, you can try this simpler variant of Carlo's solution:

  1. Put your custom snippets in ~/.vim/snippets/foo.snippets.
  2. Add the following line to your ~/.vimrc:

    augroup mySpecialHTML
        autocmd!
        autocmd BufRead,BufNewFile mySpecial.html set filetype=html.foo
    augroup END
    
romainl
  • 186,200
  • 21
  • 280
  • 313
  • Ah, there is always something new to learn about vim, I did not know about augroup feature :) – Carlo Mar 15 '14 at 12:50
0

I think you can define a new filetype just for your mySpecial.html

au BufRead,BufNewFile mySpcial.html set filetype=myHtml

And in that filetype you can reuse the html highlights group, plus your custom snippets.
Does this sound reasonable?

Carlo
  • 1,686
  • 3
  • 29
  • 43