43793

Vim and snipMate (plugin) - adding new snippet won't work

I am trying to create a new snippet to my snipMate plugin.

I work with some files called (i.e.) myfile.endfile

All .endfile files should have the same "snippet" like .html files. So I did

cp html.snippet endfile.snippet

in my ~/.vim/snippets directory.

SnipMate is working with all present snippets, but not with my new created one. Any suggestions for this problem?

(Btw: after creating the new .snippet file, I ran :helptags ~/.vim/doc command in an vim instance.)

Answer1:

It is because Snipmate works with filetype, which is a Vim option set when opening a file of a particular type.

For exemple, if you are opening, "index.html" the filetype is automatically set to html.

To see how it works, do : :e $VIMRUNTIME/filetype.vim

As a preliminary test, you can : 1. open test.endfile 2. type :set ft=endfile or :set filetype=endfile 3. Check if your defined snippets now work

To do that automatically add the following in your .vimrc : au BufNewFile,BufRead *.endfile set filetype=endfile

It means that every time you read or create a new file ending in endfilethe filetype option is set to endfile.

(The filetype is an arbitrary string it doesn't have to be identical to the file extension)

Answer2:

You can assign snippets without altering the filetype (which is desirable, because altering the filetype breaks syntax highlighting).

I believe the proper way to do this in the maintained fork of snipmate is to set g:snipMate.scope_aliases.

In your example, assuming you have an 'endfile.snippet' file, I believe adding the following to your .vimrc would work:

let g:snipMate = {} let g:snipMate.scope_aliases = {} let g:snipMate.scope_aliases['html'] = 'endfile'

If you want both html and endfile snippets to work for files of filetype='html', then use:

let g:snipMate = {} let g:snipMate.scope_aliases = {} let g:snipMate.scope_aliases['html'] = 'html,endfile'

I've added a pull request to snipmate to have their documentation updated. <strong>Edit:</strong> It has now been merged.

Answer3:

I found it convenient to use <strong>global</strong> snippets when using snippets that have uncommon name.endfile.

When you put your snippets in <strong>_.snippets</strong> file inside snippets folder they become global and are accessible in every filetype.

Maybe this is not directly answer to the question but a lot of users with similar problem can find this convenient. Specially if they don't have need to have everything organised in various files and are happy to have their own snippets in one file that is accessible everywhere.

Recommend

  • How to make a file with .pt extension, with xml syntax highlighting and vim's plugin snipmate l
  • Why FileType works and BufRead,BufNewFile doesn't - VIM?
  • Open SAS program in new instance
  • Save mail with subject as filename
  • UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb9 in position 14: invalid star
  • Vim: Find in Buffers capabilities that resembles those in TextMate
  • Vim syntax: Spell checking between certain regions
  • how to highlight variables of c/c++ files in vim
  • TinyMCE-dialogs of Plone site are not translated
  • Setting Nsight to run with existing Makefile project
  • Is it possible to retrieve an extended or full query history in google bigquery?
  • Is it OK to write code after [super dealloc]?
  • HTML file fetched using 'wget' reported as binary by 'less'
  • Excel VBA Delete Row If Misspelled Word
  • Avoiding try/catch hell in my web pages
  • No System image available when adding AVD in Android studio
  • Access 2007 forms with parameterized RecordSource
  • How is user.dir configured for Tomcat servlets?
  • Opening links in a new tab and only the new tab
  • Errno 2 using python shutil.py No such file or directory for file destination
  • How to import Navit into Eclipse and use it in own android project
  • XBee Linux Serial Port on Rasberry Pi
  • Opening two instances of InAppBrowser (_system and _blank) prevents events from triggering
  • How do I access an unhandled exception in an MVC Error view?
  • How to attach a node.js readable stream to a Sendgrid email?
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • Google Custom Search with transparent background
  • How to recover from a Spring Social ExpiredAuthorizationException
  • ILMerge & Keep Assembly Name
  • JSON with duplicate key names losing information when parsed
  • vba code to select only visible cells in specific column except heading
  • Large data - storage and query
  • WOWZA + RTMP + HTML5 Playback?
  • Use group_by to filter specific cases while keeping NAs
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory
  • How to Embed XSL into XML
  • To Get the radio button value in ruby on rails