37

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:

  1. add a map to toggle between different filetypes when I am editing different sections of the file.
  2. 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

chadgh
  • 9,063
  • 8
  • 38
  • 54
  • 1
    PHP mode in (g)VIM has support for four languages in the same file: HTML, JavaScript (though not as well-done as `ft=javascript`), CSS and PHP. It will detect the boundaries of each. The plugin was written with web programmers in mind. – amphetamachine Apr 08 '10 at 16:01
  • I do get the syntax highlighting working as expected for the files I work on with different languages in the same file, but what about other plugins? Are you saying that they should be working with (g)vim already? I don't see how this could be. – chadgh Apr 08 '10 at 17:03
  • 1
    There's not a completely general way. The plugin in question would have to be rewritten in the same way that the PHP syntax file is. They're both vim scripts; you could look at the syntax file and see how it detects the boundaries, then try to apply it. It's a hard problem in general, though, because not everything a plugin does is so neatly delimited as syntax highlighting. – Cascabel Apr 08 '10 at 17:09

1 Answers1

55

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'

Kana Natsuno
  • 1,045
  • 8
  • 13
  • 2
    Perfect! For the plugin I was mainly concerned about, this worked perfectly. Editing a PHP file I type :setfiletype html.php.js.css and the snippet plugin includes the snippet files for all of the filetypes specified. Thanks – chadgh Apr 10 '10 at 14:43
  • Excellent. I had the exact same question in regard to snipMate – devth Feb 02 '11 at 00:08
  • I clearly don`t kno anything about programming. THank yOU! for making that better. – Tegra Detra Dec 31 '12 at 17:52
  • 2
    Do you know what needs to be done to fix language support in vim? I.e. I want `set filetype python.yaml` to be able to see yaml in docstrings properly, what would i need to do to make that work? – Bastian Venthur Jul 22 '19 at 10:29
  • I have the same question as @BastianVenthur :/ – xeruf Aug 17 '20 at 16:50