I recently changed my computer and I installed vim 8 and used the new way it has for dealing with plugins.
https://shapeshed.com/vim-packages/
so I have this plugin at
~/.vim/pack/plugins/start/vim-plugin-for-drupal/plugin/drupal.vim

I noticed that .theme files where not being set as php.

I discovered that this happens at filetype.vim inside the plugin but I have no evidence that this file is sourced from plugin directories.
http://vim.wikia.com/wiki/Filetype.vim
http://vimdoc.sourceforge.net/htmldoc/filetype.html

Maybe in my old computer I had it on "$VIM/vimfiles/filetype.vim" because of some installation script or the plugin manager was sourcing that file or is sourced by 7.* and not by vim 8.*. I don't know since I have no access to it now.

The reason that other files like .module,.inc,.install are set as php is that they are supported by vim now
https://github.com/vim/vim/blob/master/runtime/filetype.vim (search for .module for example)

I did a bit of research on how this should be done I run into this
http://learnvimscriptthehardway.stevelosh.com/chapters/44.html

that says plugins should have a ftdetect folder with *.vim files.
I've seen in the git repo for this plugin that it was used before the current filetype.vim method.

I removed the extensions that are already detected by vim as php files.
I don't know since when but I can research the git repo if necessary. They are detected by vim 7.4
https://github.com/vim/vim/blob/d47d83745ff450232328ca7a4b8b00b31bad22fc...
Keeping them will be redundant since they are going to be detected as php anyway.

I removed .info.yml from being a "drini" file because I feel syntax/drini.vim doesn't bring any advantages to a yaml file.

Maybe Benji can explain a bit more about this commit:
http://cgit.drupalcode.org/vimrc/commit/?id=a9860d7ee94361b6d8a5b6874cbf...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rodrigoaguilera created an issue. See original summary.

benjifisher’s picture

Let me start with the last question (even though it was not phrased as a question). Searching the issue queue for filetype turns up #1905604: Find a better way to set filetype, which explains why I decided to move the code from ftdetect/drupal.vim into fieltype.vim.

That issue is marked as a duplicate of #1903214: You're munging my non-Drupal PHP files. Searching for that issue number clarifies things a bit:

$ git log --grep=1903214
commit 40fa87de6d05e501dc62d3d6fb5b221b3f79b909
Author: Benji Fisher <benji@FisherFam.org>
Date:   Fri Apr 12 12:17:56 2013 -0400

    Issue #1903214 by takeontom, benjifisher: Do not munge non-Drupal PHP files.
    
    This commit is empty, but the previous four make up the patch posted in #10 in
    the issue queue.
$ git log --pretty=oneline -5 40fa87d
40fa87de6d05e501dc62d3d6fb5b221b3f79b909 Issue #1903214 by takeontom, benjifisher: Do not munge non-Drupal PHP files.
6c47bc6944c351d745abeb471ff76be3320872b0 Use the right variable name. If you change your mind, change all instance of the variable.
7399915c4e99588d05ae3ee59b373eea3dbaa2d1 Replace <SID>OpenURL() with drupal#OpenURL() in ftplugin/drupal.vim.
c9a5bb1dc6456d4d599a4b7e5435be98393a1e73 Better caching for functions in autoload/drupaldetect.vim.
a9860d7ee94361b6d8a5b6874cbfa7f396fac950 Refactor code.

So I guess I was trying to separate the refactoring (intended not to change functionality) from the rest so that the remaining commits would be more atomic. Maybe I should have tagged them all with the issue number. (I do not actually remember what I was thinking; I am trying to reconstruct it.)

benjifisher’s picture

Looking at your patch, I see that you use set filetype=php. If the filetype has already been set, then this will override it and trigger the FileType event a second time. (The second point applies even if you are "changing" the filetype from php to php.) That is why :setf (long form :setfiletype) was introduced. Both the current code and fieltype.vim in the standard distribution use :setf.

The patch creates a file that does not end in a newline. Drupal coding standards require one, and vim creates one by default. (:help fixeol)

We do not need to remove the filetype detection for .module and other files. Since the existing code uses :setf, it is harmless.

As for setting the filetype for .info.yml files, there is the small advantage of omni-completion for syntax keywords. (:help ft-syntax-omni) For some reason, this is not working for me right now.

A big difference between using ftdetect/*.vim and filetype.vim is that the first is used before the default filetype detection and the second is used after it. For example, using :setf in ftdetect/drini.vim will have no effect on .info.yml files, since the filetype will already be set to yaml.

I have attached a patch that just moves the code from filetype.vim into ftdetect/*.vim, without making the other changes. I am not sure that this is the best solution, but it is there for consideration.

Another option is to recommend using :packloadall before :filetype plugin on. Then the custom filetype.vim will be run along with the others (and before the default one). This is a lot like the advice, when using Pathogen, to use :call pathogen#infect('/Users/bfisher/.drush/vimrc/bundle/{}') before :filetype plugin on. This seems like the best way to keep things working the way they do now, and it does not require any changes to our existing code. (We will have to update the documentation.)

benjifisher’s picture

I slept on it, and I think this is the right way forward. It is a big enough change that I think we should start new branches (7.x-2.x and 8.x-2.x) or do this only on the 8.x-1.x branch, so that we are changing more than a patch level in the version numbers. See #2870224: How should we use branches in the vimrc project?.

  • Rename the bundle directory to start so that it will work with the package system in Vim 8.
  • Update the drush vimrc-install command so that it adds the line call pathogen#infect('$HOME/.drush/vimrc/start/{}') (i.e., change bundle to start) for those still using Pathogen.
  • Update the documentation similarly.
  • Update the documentation for Vim 8:
    • Put the project under ~/.vim/pack/ so that you have, for example, ~/.vim/pack/vimrc/start/vim-plugin-for-drupal/plugin/drupal.vim.
    • Add the lines if v:version >= 800 | packloadall | endif to your vimrc file before filetype plugin on.

I guess also add an option to drush vimrc-install: when using VIm 8, normally install under ~/.vim/pack but give an option to install in a different directory using Pathogen (current behavior). Something like this when using Vim 8:

  • drush vimrc-install: install under ~/.vim/pack
  • drush vimrc-install --pathogen-dir: install under ~/.drush (current behavior)
  • drush vimrc-install --pathogen-dir=/opt/vim: install under /opt/vim

I have attached a patch that moves bundle to start. To test, you can try this (or just move the directory yourself), put the whole thing under ~/.vim/pack, and add packloadall to your vimrc file before filetype plugin on.

dshumaker’s picture

I'm having the same & related issue. I'm on a d7 site, using Vim 8. So I'm not having issues with yaml files but with drini.drupal syntax's not being set correctly for info files. I assume because the filetype has already been set. I load a my_module.info file and

:set filetype and it's set to ini.drupal - which doesn't change any colors and not sure where that's comming from. However, if I manually ::set filetype=drini.drupal, then everything looks great.

All that to say that I noticed the ftdetect directory is gone but still mentioned in the patches (which lead me here). I added instructions for the Plugin manager I'm using here: https://www.drupal.org/node/1389448#plug and at first thought it was the fault of Plug ( https://github.com/junegunn/vim-plug/issues/626 ) ..

Just adding my 2 cents about other people that are in favor of vim plugin managers other than pathogen (or in your case drush) -- and yet still hope to use the vimrc plugin. Many thanks for the plugin btw!!

benjifisher’s picture

@dshumaker:

Thanks for updating the documentation.

Did you try the instructions at the end of my previous comment? In order to get the .info file recognized, I think the key step is to call :packloadall before :filetype plugin on.

I am not sure it will help here, but :verbose set ft? will give you more information than :set ft?.

BTW, have you joined the #vim channel on Drupal Slack?

dshumaker’s picture

@benjifisher , When I put packloadall before the filetype plugin on line in my vimrc it does not fix the issue. Here is the output of :verbose set ft

  filetype=ini.drupal
          Last set from ~/.vim/plugged/vimrc/bundle/vim-plugin-for-drupal/plugin/drupal.vim
benjifisher’s picture

Oh, :packloadall will not help if your plugin manager is not built on top of the package system introduced in Vim 8.

Looking at the vim-plug docs, it updates 'runtimepath' and then calls :filetype plugin indent on. That should work. You can check

:set rtp?

and it should include ~/.vim/plugged/vimrc/bundle/vim-plugin-for-drupal.

IIRC, drupal.vim adds .drupal to the filetype, but 'filetype' was already set to ini before it got there. As I suspected, using :verbose does not help in this case.

Probably something else is setting 'filetype' to ini before vim-plug runs :filetype plugin indent on. Do you have a :filetype line in your vimrc file before the vim-plug lines?

The best way to debug the problem is

:redir @a
:scriptnames
:redir END
:new
:put a
/filetype\.vim

(You will probably have to hit <CR> a few times at the more prompt after :scriptnames.) That should show you which filetype.vim file is called first, and where it is called from.

dshumaker’s picture

Wow, that redir thing is a neat trick. Unfortunately it looks like Vim8 is only thing before the vimrc plugin is called.

Here's the order:

  1: ~/.vimrc
  2: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/syntax/syntax.vim
  3: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/syntax/synload.vim
  4: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/syntax/syncolor.vim
  5: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/filetype.vim
  6: ~/.vim/autoload/plug.vim
  7: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/ftoff.vim
  8: ~/.vim/plugged/vimrc/bundle/vim-plugin-for-drupal/filetype.vim
  9: ~/.vim/plugged/vimrc/bundle/vim-plugin-for-drupal/autoload/drupaldetect.vim
 10: ~/.vim/plugged/vim-markdown/ftdetect/markdown.vim
 11: ~/.vim/plugged/vim-javascript/ftdetect/javascript.vim
 12: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/ftplugin.vim
 13: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/indent.vim
 14: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/syntax/nosyntax.vim
 15: ~/.vim/plugged/vim-color-spring-night/colors/spring-night.vim
 16: ~/.vim/plugged/vim-sensible/plugin/sensible.vim
 17: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/macros/matchit.vim
 18: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/pack/dist/opt/matchit/plugin/matchit.vim
 19: ~/.vim/plugged/vim-fugitive/plugin/fugitive.vim
 20: ~/.fzf/plugin/fzf.vim
 21: ~/.vim/plugged/fzf.vim/plugin/fzf.vim
 22: ~/.vim/plugged/vim-scriptease/plugin/scriptease.vim
 23: ~/.vim/plugged/tabline.vim/plugin/tabline.vim
 24: ~/.vim/plugged/ag.vim/plugin/ag.vim
 25: ~/.vim/plugged/nerdtree/plugin/NERD_tree.vim
 26: ~/.vim/plugged/nerdtree/autoload/nerdtree.vim
 27: ~/.vim/plugged/nerdtree/lib/nerdtree/path.vim
 28: ~/.vim/plugged/nerdtree/lib/nerdtree/menu_controller.vim
 29: ~/.vim/plugged/nerdtree/lib/nerdtree/menu_item.vim
 30: ~/.vim/plugged/nerdtree/lib/nerdtree/key_map.vim
 31: ~/.vim/plugged/nerdtree/lib/nerdtree/bookmark.vim
 32: ~/.vim/plugged/nerdtree/lib/nerdtree/tree_file_node.vim
 33: ~/.vim/plugged/nerdtree/lib/nerdtree/tree_dir_node.vim
 34: ~/.vim/plugged/nerdtree/lib/nerdtree/opener.vim
 35: ~/.vim/plugged/nerdtree/lib/nerdtree/creator.vim
 36: ~/.vim/plugged/nerdtree/lib/nerdtree/flag_set.vim
 37: ~/.vim/plugged/nerdtree/lib/nerdtree/nerdtree.vim
 38: ~/.vim/plugged/nerdtree/lib/nerdtree/ui.vim
 39: ~/.vim/plugged/nerdtree/lib/nerdtree/event.vim
 40: ~/.vim/plugged/nerdtree/lib/nerdtree/notifier.vim
 41: ~/.vim/plugged/nerdtree/autoload/nerdtree/ui_glue.vim
 42: ~/.vim/plugged/nerdtree/nerdtree_plugin/exec_menuitem.vim
 43: ~/.vim/plugged/nerdtree/nerdtree_plugin/fs_menu.vim
 44: ~/.vim/plugged/vim-nerdtree-tabs/nerdtree_plugin/vim-nerdtree-tabs.vim
 45: ~/.vim/plugged/vdebug/plugin/vdebug.vim
 46: ~/.vim/plugged/vim-airline/plugin/airline.vim
 47: ~/.vim/plugged/vim-airline/autoload/airline.vim
 48: ~/.vim/plugged/vim-airline/autoload/airline/init.vim
 49: ~/.vim/plugged/vim-airline/autoload/airline/parts.vim
 50: ~/.vim/plugged/vimwiki/plugin/vimwiki.vim
 51: ~/.vim/plugged/calendar.vim/plugin/calendar.vim
 52: ~/.vim/plugged/tmuxline.vim/plugin/tmuxline.vim
 53: ~/.vim/plugged/auto-pairs/plugin/auto-pairs.vim
 54: ~/.vim/plugged/tagbar/plugin/tagbar.vim
 55: ~/.vim/plugged/vim-better-whitespace/plugin/better-whitespace.vim
 56: ~/.vim/plugged/nerdcommenter/plugin/NERD_commenter.vim
 57: ~/.vim/plugged/tlib_vim/plugin/02tlib.vim
 58: ~/.vim/plugged/vim-snipmate/plugin/snipMate.vim
 59: ~/.vim/plugged/vim-addon-mw-utils/autoload/funcref.vim
 60: ~/.vim/plugged/vim-snippets/plugin/vimsnippets.vim
 61: ~/.vim/plugged/drupal-snippets/plugin/snipMate_drupal.vim
 62: ~/.vim/plugged/neocomplete.vim/plugin/neocomplete/buffer.vim
 63: ~/.vim/plugged/neocomplete.vim/plugin/neocomplete/dictionary.vim
 64: ~/.vim/plugged/neocomplete.vim/plugin/neocomplete/member.vim
 65: ~/.vim/plugged/neocomplete.vim/plugin/neocomplete/tag.vim
 66: ~/.vim/plugged/neocomplete.vim/plugin/neocomplete.vim
 67: ~/.vim/plugged/vimrc/bundle/vim-plugin-for-drupal/plugin/drupal.vim
 68: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/getscriptPlugin.vim
 69: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/gzip.vim
 70: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/logiPat.vim
 71: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/manpager.vim
 72: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/matchparen.vim
 73: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/netrwPlugin.vim
 74: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/rrhelper.vim
 75: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/spellfile.vim
 76: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/tarPlugin.vim
 77: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/tohtml.vim
 78: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/vimballPlugin.vim
 79: /usr/local/Cellar/vim/8.0.0543/share/vim/vim80/plugin/zipPlugin.vim
 80: ~/.vim/plugged/vim-snipmate/after/plugin/snipMate.vim
 81: ~/.vim/plugged/vimrc/bundle/vim-plugin-for-drupal/ftplugin/drini.vim
 82: ~/.vim/plugged/vimrc/bundle/vim-plugin-for-drupal/syntax/drini.vim
 83: ~/.vim/plugged/vimrc/bundle/vim-plugin-for-drupal/syntax/drupal.vim
 84: ~/.vim/plugged/vim-airline/autoload/airline/extensions.vim
 85: ~/.vim/plugged/vim-airline/autoload/airline/extensions/quickfix.vim
 86: ~/.vim/plugged/vim-airline/autoload/airline/extensions/netrw.vim
 87: ~/.vim/plugged/vim-airline/autoload/airline/extensions/tagbar.vim
 88: ~/.vim/plugged/vim-airline/autoload/airline/extensions/branch.vim
 89: ~/.vim/plugged/vim-airline/autoload/airline/extensions/whitespace.vim
 90: ~/.vim/plugged/vim-airline/autoload/airline/extensions/tmuxline.vim
 91: ~/.vim/plugged/vim-airline/autoload/airline/section.vim
 92: ~/.vim/plugged/vim-airline/autoload/airline/highlighter.vim
 93: ~/.vim/plugged/vim-color-spring-night/autoload/airline/themes/spring_night.vim
 94: ~/.vim/plugged/vim-airline/autoload/airline/themes.vim
 95: ~/.vim/plugged/vim-airline/autoload/airline/util.vim
 96: ~/.vim/plugged/tmuxline.vim/autoload/tmuxline/api.vim
 97: ~/.vim/plugged/tmuxline.vim/autoload/tmuxline/util.vim
 98: ~/.vim/plugged/tmuxline.vim/autoload/tmuxline.vim
 99: ~/.vim/plugged/tmuxline.vim/autoload/tmuxline/presets/powerline.vim
100: ~/.vim/plugged/tmuxline.vim/autoload/tmuxline/builder.vim
101: ~/.vim/plugged/vim-airline/autoload/airline/builder.vim
102: ~/.vim/plugged/vim-airline/autoload/airline/extensions/default.vim
103: ~/.vim/plugged/vimrc/bundle/vim-plugin-for-drupal/ftplugin/drupal.vim
104: ~/.vim/plugged/vimrc/bundle/vim-plugin-for-drupal/autoload/drupal.vim
105: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/init.vim
106: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete.vim
107: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/variables.vim
108: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/filters/matcher_fuzzy.vim
109: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/util.vim
110: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/filters/matcher_length.vim
111: ~/.vim/plugged/neocomplete.vim/autoload/vital/neocomplete.vim
112: ~/.vim/plugged/neocomplete.vim/autoload/vital/_neocomplete/Prelude.vim
113: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/commands.vim
114: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/mappings.vim
115: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/context_filetype.vim
116: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/sources/buffer.vim
117: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/custom.vim
118: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/filters/sorter_rank.vim
119: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/filters/converter_remove_last_paren.vim
120: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/filters/converter_remove_overlap.vim
121: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/filters/converter_delimiter.vim
122: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/filters/converter_abbr.vim
123: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/sources/dictionary.vim
124: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/sources/file.vim
125: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/filters/sorter_filename.vim
126: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/sources/member.vim
127: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/sources/omni.vim
128: ~/.vim/plugged/neocomplete.vim/autoload/vital/_neocomplete/Data/List.vim
129: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/sources/tag.vim
130: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/handler.vim
131: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/helper.vim
132: ~/.vim/plugged/neocomplete.vim/autoload/neocomplete/complete.vim

I'm curious if the order of the plugins loaded by "Plug" matters?

benjifisher’s picture

Unfortunately it looks like Vim8 is only thing before the vimrc plugin is called.

Yes, that is the problem. The fourth file loaded after your vimrc file is the default filetype.vim. It looks as though you have something like :syntax on and :filetype on in your vimrc file before you load packages with vim-plug. If you remove the :filetype on line, that should fix the problem.

:help :setf
dshumaker’s picture

@benjifisher, Turns out it was the https://github.com/technosophos/drupal-snippets plugin that was causing issues. Once I un-installed that, the drini.drupal filetype is used. Sad that I won't be using the drupal-snippets plugin but for now I'll live. :) Thanks for your help. I'm not sure what that plugin was doing to mess things up.

dshumaker’s picture

benjifisher’s picture

Maybe we can convince drupal-snippets that We are the Borg. We will assimilate you!

Seriously, this project has snippet support (which could use some love) and a whole lot more. I would be happy to see a patch to add more snippets.

And, in the vaporware department, #2845717: Add support for Drupal Console.