Sudar
Sudar

Reputation: 19992

Is it possible to include snippets from file in snipmate

I am using the vim-snipmate addon with these snippets.

I am currently in the process of creating a snippet file for Arduino. I realized that all the snippets for the c language also holds good for Arduino.

Instead of just copy pasting them, I am thinking of including the entire c file and then just add Arduino specific parts.

So my question is, is it possible to include snippets from other file into your snippet file?

Upvotes: 2

Views: 436

Answers (5)

ArtBIT
ArtBIT

Reputation: 3989

Add the following to the $VIMRUNTIME/after/plugin/snipMate.vim file:

call ExtractSnipsFile(g:snippets_dir.'arduino.snippets', 'c')

This will parse and initialize the arduino.snippets file for .c filetype.

Basically it just loads the snippets from that file, and adds them to the specified filetype, in your case c file.

For help about using ExtractSnipsFile see :help ExtractSnipsFile or see the Doc file on GitHub

EDIT 2018.03.14

It is possible to load multiple snippet files for the same filetype using UltiSnipsAddFiletypes. If, for an example, you want to load .c snippets when editing an .arduino file, just add the following line to your ftplugins/arduino.vim: UltiSnipsAddFiletypes arduino.c

Upvotes: 0

wataya
wataya

Reputation: 246

You asked specifically about snipmate, so this may be somewhat off the mark, but anyhow: there's also a plugin called UltiSnips that is quite similar to snipmate (with some additional functionality). In UltiSnips' snippet files you can use the extends statement that does exactly what you asked for.

Upvotes: 1

Tzu ng
Tzu ng

Reputation: 9244

@Sudar: Your approach is good but it's not necessary if you have a another config or lang later, your vimrc will be bloated.

just create arduino.snippets in snipmate then :set ft=c.arduino . Snipmate identifies snippets due to its filetype

Upvotes: 2

Sudar
Sudar

Reputation: 19992

(I found the answer to this question, after searching the documentation of the snipmate Plugin)

I can't include a snippet file in another snippet file, but I can include more than one snippet for a certain file type. I have declared the following in my .vimrc now and it works.

" Add c snippets to Arduino
let g:snipMate = {}
let g:snipMate.scope_aliases = {} 
let g:snipMate.scope_aliases['arduino'] = 'arduino,c'

I am using this with the arduino snippets that I created.

Upvotes: 3

romainl
romainl

Reputation: 196506

No. You need to yank/paste those snippets over to your arduino.snippets file.

Upvotes: 0

Related Questions