garbas / vim-snipmate

snipMate.vim aims to be a concise vim script that implements some of TextMate's snippets features in Vim.
www.vim.org/scripts/script.php?script_id=2540
2.01k stars 181 forks source link

Apply snippets to multiple filetypes #293

Closed TroySigX closed 1 year ago

TroySigX commented 1 year ago

2 filetypes, tex and plaintex, sometimes used interchangeably, and I want to apply my latex snippets for both filetypes. And constantly having to copy between directories is very inconvenient. Any idea how to solve this?

shmibs commented 1 year ago

not quite sure what the question is, but maybe you could either make plaintex.snippets be a symlink to tex.snippets in .vim/snippets/, or else put au! BufRead,BufNewFile *.tex set filetype=tex in .vim/ftdetect/tex.vim, to make all .tex files loaded as one filetype?

TroySigX commented 1 year ago

Is there a way to create a group of filetypes in snipmate that share the same snippet?

ajzafar commented 1 year ago

@TroySigX This is exactly the sort of situation for which scope aliases were added (documented under :h SnipMate-options). Basically:

let g:snipMate.scope_aliases = {}
let g:snipMate.scope_aliases['foo'] = 'foo,bar'

The first line is just necessary to create the variable. The second line says "Whenever SnipMate loads a foo file, load both foo and bar snippets".

For your situation, this would result in something like the following:

let g:snipMate.scope_aliases = {}
let g:snipMate.scope_aliases['tex'] = 'tex,plaintex'
let g:snipMate.scope_aliases['plaintex'] = 'tex,plaintex'

These lines can go in your vimrc.

I'm going to close this as I think this sufficiently resolves the problem, but I'd be happy to answer more questions in this issue on this topic if you have them.

ajzafar commented 1 year ago

@TroySigX I'm sorry, I didn't see your most recent question until just now. If I understand it correctly, this can be done with scope aliases. Place all the snippets into a .snippets file named however you want (but it should be something that is unlikely to be a filetype). For example, giantsub.snippets. Then create the scope aliases:

let g:snipMate.scope_aliases = {}
let g:snipMate.scope_aliases['tex'] = 'plaintex,tex,giantsub'
let g:snipMate.scope_aliases['plaintex'] = 'plaintex,tex,giantsub'
TroySigX commented 1 year ago

Thank you very much @ajzafar!