Multiple file types in vim - 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'

Related

Change the markup/detected-language of a file

Is it possible to change the language that is detected in a vim file? For example, in TextMate, there is a language dropdown so that you can, for example, change a file from one language to another:
Also, sometimes I will have a json object in a python file, or some javascript in html, etc. I don't exact it to be able to mark-up each section properly, though it would be nice to be able to change the language-detected-formatted accordingly. Is this possible in vim?
Is it possible to change the language that is detected in a vim file? For example, in TextMate, there is a language dropdown so that you can, for example, change a file from one language to another:
Yes, it is! You can manually change the filetype (language) of files by setting the filetype option:
:set filetype=html
More information is available in the documentation.
Also, sometimes I will have a json object in a python file, or some javascript in html, etc. I don't exact it to be able to mark-up each section properly, though it would be nice to be able to change the language-detected-formatted accordingly. Is this possible in vim?
I have not tried this myself, but there are some solutions in the Vim Tips Wiki: Different syntax highlighting within regions of a file

vim-snipmate not expanding non-source code file

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.

How can I configure VIM so that files with extension .less are edited with zen-coding?

How can I configure VIM so that files with extension .less are edited with zen-coding?
I can use within the zencoding notepad + + on windows normally. But now I want to use the same way inside vim.
ZenCoding is probably activated on a per-filetype basis, if that's the case, just type :set filetype=css.
If you want this setting to stick, add this line to your .vimrc:
autocmd BufRead,BufNewFile *.less set filetype=css
If you want to retain the normal features that go with .less files (if any) you can do :set ft=less.css but some plugins don't like that.
I first tried to write a comment, but found then something that could be an answer.
So I think the question is: How can I configure VIM so that files with extension .less are edited with zen-coding?
At the official site for zen-coding, there are lists of editors that support zen-coding:
Official
third-party
Unofficial
There for VIM, the following sites are mentioned:
Sparkup
Zen Coding for VIM
I have read into both, and both seem to expand shortcuts to HTML code, not to less-code. But perhaps I have misunderstood the question.
I didn't know you could use Zencoding for css. I use it in Vim for html.It s great!I started using Less and I was wondering an hour ago ,If something like this existed. I guess it's something to work on.

How do I combine two features of vim wiki plugins?

Sorry in advance for the newbie question. I've been trying to use vim for keeping a personal wiki, but I can't quite seem to decide on a good plugin. Vimwiki is great, and I really like the way it does checkboxes and uses the enter key to follow links. Notes.vim is simpler but I like it a lot better: it dynamically makes names of notes into links like Tomboy Notes, makes pretty bullet points, and has a search function built in. I can't get vimwiki to use files with no extension, but notes.vim does that automatically.
What I want to know is: is there an easy way (calling a vimscript file or something?) to combine some features of both of these plugins? I've tried doing some cutting-and-pasting but so far nothing has been working.
I doubt whether tbere is any simple automated way to do it. Both Vimwiki and notes.vim are "filetype" plugins. Generally in Vim any file (or buffer) can be set to just a single filetype.
It would depend on how the ftplugins were written, but it may be possible to apply them both to same buffer by making sure that the buffer is set to both filetypes, sequentially. That is, the buffer can be set to one filetype at a time, but setting it to both one after the other may do part of what you need.
For example, opening a notes.vim file will automatically set the buffer to a notes.vim filetype. Once open you could issue the command :setlocal filetype=vimwiki to change it to a vimwiki buffer. If vimwiki filetype initialization doesn't wipe out crucial notes.vim settings or have conflicting operation then you may then be able to access some functionality from both ftplugins. Not likely to get you very far, but maybe worth a try. Better would be to combine sections of their code into a single ftplugin.

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

Resources