Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple file types in vim

Tags:

vim

file-type

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

like image 889
chadgh Avatar asked Apr 08 '10 15:04

chadgh


People also ask

How do I open multiple files in vim?

Ctrl-W w to switch between open windows, and Ctrl-W h (or j or k or l ) to navigate through open windows. Ctrl-W c to close the current window, and Ctrl-W o to close all windows except the current one. Starting vim with a -o or -O flag opens each file in its own split.

How do I make multiple tabs in vim?

To directly move to first tab or last tab, you can enter the following in command mode: :tabfirst or :tablast for first or last tab respectively. To move back and forth : :tabn for next tab and :tabp for previous tab. You can list all the open tabs using : :tabs. To open multiple files in tabs: $ vim -p source.

What is vim Ftplugin?

A file type plugin (ftplugin) is a script that is run automatically when Vim detects the type of file when the file is created or opened. The type can be detected from the file name (for example, file sample. c has file type c ), or from the file contents.

How do I switch between vim files?

Switch between files Here, N is capital (Type SHIFT+n). Start editing the files as the way you do with Vim editor. Press 'i' to switch to interactive mode and modify the contents as per your liking. Once done, press ESC to go back to normal mode.


1 Answers

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'

like image 168
Kana Natsuno Avatar answered Oct 02 '22 14:10

Kana Natsuno