How to make a file with .pt extension, with xml syntax highlighting and vim's plugin snipmate load pt.snippets?
Asked Answered
L

3

0

I have the following in my .vimrc:

au BufNewFile,BufRead *.pt set filetype=xml

This is needed because although I'm editing a file with *.pt extension, it's indeed a valid xml file: setting the filetype like this I can have syntax highlighting.

I'm using vim's snipmate plugin, and tried to create pt.snippets to specific needs since these files are Zope Page Templates (ZPT with TAL).

Now, I have a problem: I don't want to create these snippets in xml.snippets, since they aren't really generic xml snippets, but my *.pt files are set to xml, so when I define my pt snippets they aren't loaded unless I run :set filetype=pt on my pt file on vim - but then I lose syntax highlighting.

I would like to be able to have a pt file, with xml syntax highlighting, to be able to load a pt.snippets file from snipmate. How can I do it?

(I would like to avoid putting my snippets in a generic snippet file, I would like it to be present only in pt.snippets to be easier to maintain.)

Lundt answered 8/6, 2010 at 18:5 Comment(0)
F
2

Snipmate allows for dotted 'filetype' syntax, try:

au BufNewFile,BufRead *.pt set filetype=xml.pt

Further answered 9/6, 2010 at 15:57 Comment(0)
S
3

the syntax is notoriously finnicky for not wanting to support two concurrent filetypes (actually, someone asked this same question yesterday)

au BufRead *.pt set filetype=xml.pt
au BufNewFile *.pt set filetype=xml.pt

jinfield's answer is actually spot-on, but I have had the comma-syntax fail on some versions of vim

Sites answered 12/6, 2010 at 14:3 Comment(2)
sleepynate, thanks for answering. Strange enough, jinfields answer is working!! Don't know why it wasn't before, I think I did something wrong... thanks anyway for your comma-syntax suggestion.Lundt
Yea, no problem. I have had the same issue with it failing when wanting to use both php and html snippets in CakePHP templates.Sites
F
2

Snipmate allows for dotted 'filetype' syntax, try:

au BufNewFile,BufRead *.pt set filetype=xml.pt

Further answered 9/6, 2010 at 15:57 Comment(0)
N
1

How about?:

autocmd BufNewFile,BufRead *.pt setlocal filetype=pt
autocmd BufNewFile,BufRead *.pt setlocal syntax=xml
Need answered 8/6, 2010 at 21:24 Comment(3)
"setlocal" doesn't work, but doing "autocmd BufNewFile,BufRead *.pt set filetype=pt" works. Can you explain why?Lundt
I'm not sure why it doesn't work for you. The above 'autocmd's along with a very simple pt.snippets seem to be working for me (Vim 7.2, snipMate 0.83). If you run the above commands (just the "setlocal..." part) by hand, does it work as expected?Need
Yes, it works... but strange enough, I have a colorscheme named "molokai". When I run the first command (filetype=pt), it loses the colorscheme. When I run "syntax=xml", it recovers a colorscheme, but instead of molokai I think it gets the standard vim xml syntax.Lundt

© 2022 - 2024 — McMap. All rights reserved.