vim-snipmate not expanding non-source code file - vim

I am using snipmate for coding and it works fine.
However I would also like to use it on txt file extension, but this does not work at all.
Is it designed to work like that? How can I get snippet expansion on ad-hoc file types?

*.txt files have the text filetype but you probably don't have snippets for that filetype. You can create them in ~/.vim/snippets/text.snippets and do the same for every filetype for which you don't have snippets.
Note that the snippets in ~/.vim/snippets/_.snippets are "global" and thus available in any filetype.
If you want to expand JavaScript snippets in an HTML file, you can "combine" filetypes with :set ft=html.javascript.

Related

vim snippet default snippet file issue

I installed Vundle, got the snippetMate running. But when vim launched, the snippet it loaded is _.snippets. With my Understanding, it is the default for snippet. However, i want to use other snippet such as sh.snippets and tex.snippets. I try to run the SnippetMateOpenFile in Vim to locate the snippets file It doesn't appear. I checked and see that all of the snippet file is there.
Yes, the _.snippets contains the global snippets. In order to use the other ones, the correct filetype has to be set. The snippet plugin reuses the same mechanism that Vim uses for syntax highlighting and settings (like indent) that are specific to a certain programming language. Usually, filetype detection works automatically; you can check with
:verbose setlocal filetype?
This needs to print sh for shell scripts, to use sh.snippets. If it doesn't, you have to fix / enable filetype detection (see :help filetype-detect), or, for a one-time fix, set it manually:
:setf sh
(I'm not sure about your particular snippet plugin; I guess it's snipMate, but there are multiple variants around.)
I found out what happened. the snippets won't recognize the snippet files rightaway. So i saved and exit the text and reopen vim again. It works, yet seems like there must be a certain tag in order for vim to recognize the format of the file.

How can I disable the vim plugim snipMate to some kind of files?

My questions is self-explanatory, How can I disable vim snipmate to perl files for example?? I found myself frustating because its stuck with my omni-completion and neocomplcache. I just use snipMate in html files.
This same question could be asked like: How can I enable snipmate for just one type of file (html)?
You could move the snipMate.vim file from $VIM/plugin to another directory that is not autoloaded, like $VIM/extra.
Then in your .vimrc, add a line to use snipmate for HTML only:
autocmd FileType html,xhtml source $VIM/extra/snipMate.vim
Another uglier method would be to simply remove or rename all the snippets files in $VIM/snippets except for html.snippets, or a subset of those you would like to keep. This would be more effective though if you only wanted to remove some (like only disabling perl, for example) than to disable all but one type.

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

Coda Clips for Vim

I'm currently trying to switch from Coda (a Mac IDE) to Vim. One thing I loved about Coda and my knowledge of Vim cannot replace were the so-called "clips". Basically, you type, say, "new", press TAB, and the text is replaced with a basic XHTML page. And you can add as many keyword/clips combinations as you want.
The most I could get with Vim so far was to create a new file containing my clip, and then use :r FILE in Vim in order to get it inserted, but this is not a very elegant solution, as I'd have to carry these clips around in every directory I have a file I want to use my clips with.
So assuming I've explained things properly, what would be my choices?
For various editors, there's a functionality called '''snippets''' which tab expands the beginnings of common text (like a HTML div, or C function definition) into a skeleton for that code.
There's a couple vim plugins that present this functionality. Two off the top of my bookmark list:
snippetsEmu
snipMate
I heard of another plugin for quick HTML editing that uses snippets recently:
zencoding
Check those out and see if they're near what you're looking for.
Also, you can define a default BufNewFile action in vim - which lets you read in a skeleton for a file if it doesn't already exist automatically.
*skeleton* *template*
To read a skeleton (template) file when opening a new file: >
:autocmd BufNewFile *.c 0r ~/vim/skeleton.c
:autocmd BufNewFile *.h 0r ~/vim/skeleton.h
:autocmd BufNewFile *.java 0r ~/vim/skeleton.java
Put those (or the equivalent) in your .vimrc (w/o the leading colon) to have them set up automatically every time you run vim.
Very late to the party, but:
I would recommend something like Dash for this, because the snippets are then available across all your apps.
This can be a significant bonus as your muscle-memory starts to rely on particular snippets, and can also ease the transition from one editor to the other, because your snippets are independent.
Sometimes I find myself using snippets in something like Mail to send to someone else, or in a Vim terminal on a remote machine I haven't configured, and it's great to have them all there at the ready.
Now all we need is a cross-platform solution which moves with you to a colleague's machine!
As well as the various snippet plugins, Vim also has an abbreviation feature built in, using the :ab[breviate] command.
For example you can define this:
:ab <h <head>^M</head>^M<body>^M<\body>
Then when you type <h<SPACE> it will expand into the full text. The ^M in the example above are actually carriage returns inserted in the string definition with <ctrl-V><RETURN>.

Multiple file types in vim

When I am working on a PHP file for example the default filetype is php. This makes sense, however when that PHP file has HTML as well the filetype is still only php. For some plugins that means that I get the PHP functionality for that plugin, but miss out on the HTML functionality.
A more specific situation where this happens is with my snippet plugin. I get php snippets and not html snippets when I am editing a php file.
Possible solutions to this (which I obviously don't like, hence my posting this question) are:
add a map to toggle between different filetypes when I am editing different sections of the file.
update my php snippets file to include the html snippets as well (while this would work for the example above, it doesn't solve the fundamental problem).
So, Is there a way to edit a file using multiple filetypes at the same time in vim?
Edit: For future reference the specific plugin that I am talking about is called snipMate. http://www.vim.org/scripts/script.php?script_id=2540
You can specify to use multiple filetypes at the same time. For example:
:setfiletype html.php
But most of filetype plugings and syntax files are not designed for such cases.
See also :help 'filetype'

Resources