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...
Comment | File | Size | Author |
---|---|---|---|
#4 | 2845607-ftdetect-vim-4.patch | 4.03 KB | benjifisher |
#3 | 2845607-ftdetect-vim-3.patch | 1.52 KB | benjifisher |
ftdetect-vim.patch | 1.21 KB | rodrigoaguilera |
Comments
Comment #2
benjifisherLet 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 fromftdetect/drupal.vim
intofieltype.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:
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.)
Comment #3
benjifisherLooking 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 fromphp
tophp
.) That is why:setf
(long form:setfiletype
) was introduced. Both the current code andfieltype.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
andfiletype.vim
is that the first is used before the default filetype detection and the second is used after it. For example, using:setf
inftdetect/drini.vim
will have no effect on.info.yml
files, since the filetype will already be set toyaml
.I have attached a patch that just moves the code from
filetype.vim
intoftdetect/*.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 customfiletype.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.)Comment #4
benjifisherI 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?.
bundle
directory tostart
so that it will work with the package system in Vim 8.drush vimrc-install
command so that it adds the linecall pathogen#infect('$HOME/.drush/vimrc/start/{}')
(i.e., changebundle
tostart
) for those still using Pathogen.~/.vim/pack/
so that you have, for example,~/.vim/pack/vimrc/start/vim-plugin-for-drupal/plugin/drupal.vim
.if v:version >= 800 | packloadall | endif
to your vimrc file beforefiletype 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
tostart
. To test, you can try this (or just move the directory yourself), put the whole thing under~/.vim/pack
, and addpackloadall
to your vimrc file beforefiletype plugin on
.Comment #5
dshumaker CreditAttribution: dshumaker commentedI'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!!
Comment #6
benjifisher@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?
Comment #7
dshumaker CreditAttribution: dshumaker commented@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
Comment #8
benjifisherOh,
: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 checkand it should include
~/.vim/plugged/vimrc/bundle/vim-plugin-for-drupal
.IIRC,
drupal.vim
adds.drupal
to the filetype, but'filetype'
was already set toini
before it got there. As I suspected, using:verbose
does not help in this case.Probably something else is setting
'filetype'
toini
beforevim-plug
runs:filetype plugin indent on
. Do you have a:filetype
line in your vimrc file before thevim-plug
lines?The best way to debug the problem is
(You will probably have to hit
<CR>
a few times at themore
prompt after:scriptnames
.) That should show you whichfiletype.vim
file is called first, and where it is called from.Comment #9
dshumaker CreditAttribution: dshumaker commentedWow, 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:
I'm curious if the order of the plugins loaded by "Plug" matters?
Comment #10
benjifisherYes, 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 withvim-plug
. If you remove the:filetype on
line, that should fix the problem.Comment #11
dshumaker CreditAttribution: dshumaker commented@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.
Comment #12
dshumaker CreditAttribution: dshumaker commentedAh, ha: The smoking gun: https://github.com/technosophos/drupal-snippets/blob/master/plugin/snipM...
Submitted pr: https://github.com/technosophos/drupal-snippets/pull/3/files
Comment #13
benjifisherMaybe 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.