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

╄→гoц情女王★ 提交于 2019-12-24 02:50:35

问题


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.)


回答1:


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)




回答2:


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. Edit: It has now been merged.




回答3:


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

When you put your snippets in _.snippets 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.



来源:https://stackoverflow.com/questions/4488786/vim-and-snipmate-plugin-adding-new-snippet-wont-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!