Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As is, the .vimrc file is global to all uses of Vim. This is a pain when dealing with other projects or languages that might have different coding standards. We should figure out the best way to structure our customizations so they will only apply to Drupal code.
I'm thinking that doing filetype detection and setting the filetype to "php.drupal", "css.drupal" and so on might work. I'd be very happy if we could get our setup instructions down to "extract the project to ~/.vim/drupalrc, add source ~/.vim/drupalrc/vimrc to ~/.vimrc" or similar.
Comment | File | Size | Author |
---|---|---|---|
#14 | ultimate_vimrc.tgz | 2.76 KB | benjifisher |
#12 | ultimate_vimrc.tgz | 2.23 KB | benjifisher |
#10 | ultimate_vimrc.tgz | 1.95 KB | benjifisher |
#8 | vimrc-play-nice-1140306-8.patch | 9.34 KB | benjifisher |
Comments
Comment #1
kostajh CreditAttribution: kostajh commentedThat makes sense, good suggestion!
Comment #2
skottler CreditAttribution: skottler commentedI think the ultimate way to fix the issues you outline (which are clearly evident to most users of this project) is to move this over to a vim plugin. Therefore, no modifications will be required to install locally. Additionally, as #1145580: Add installer? outlines, we could implement an installer if this change was made.
Comment #3
skottler CreditAttribution: skottler commentedComment #4
benjifisherDo you mean a plugin or a filetype plugin (ftplugin)?
A plugin is a vim script that is run every time vim starts. (There are some exceptions.
:help load-plugins
) For example, gzip.vim automatically invokes gunzip when you edit foo.gz (and compress or bzip2 for .Z and .bz2). If you are not using the matchit plugin, you should be.:help matchit-install
An ftplugin is a vim script that is loaded when you edit a particular filetype. I keep all of my drupal tweaks in
~/.vim/after/ftplugin/php_drupal.vim
so that they are loaded whenever I edit a PHP file (and they are loaded after the standard ftplugin for PHP). In order for this to work, the autocommands that tell vim to treat .module and other files as PHP should be included in a filetype.vim file or in an ftdetect directory.I have some experience writing vim scripts and configuring vim, so I can do a lot of the coding if you tell me what you want.
Comment #5
benjifisherI suggest the following file structure. I assume that it will be fairly easy to write an installer that copies this structure from the distributed
vimrc/
directory to the user's vimfiles directory. (On Unix, the default vimfiles directory is$HOME/.vim/
but other OS's have other defaults.)plugin/drupal.vim
, as well as the:filetype
and:syntax
commands.ftdetect/drupal.vim
.ftplugin/php.vim
.I assume that we do not want to make a separate filetype, but this is debatable. The issue summary suggests css.drupal and php.drupal, for example. If we want to make it easy for those who code for Drupal and also do other PHP coding with other coding standards, we can make the ftplugin and syntax files bail out if we are not in a Drupal directory.
If we are afraid that there will be other drupal.vim files from other projects, then we can use
ultimate_drupal_vimrc.vim
or something instead ofdrupal.vim
.Comment #6
skottler CreditAttribution: skottler commented@benjifisher, I agree that what you described is probably the best way to do this. As a proof of concept can you provide a patch to move the existing vimrc functionality into the drupal.vim plugin?
Comment #7
benjifisherSo just replace
vimrc/.vimrc
withvimrc/plugin/drupal.vim
as a first step? Sure, give me a minute or two.I would like to be added as a maintainer of this project. I may still be a beginner at Drupal, but I know vim well.
Comment #8
benjifisherHere is the patch. I spent some time with the git docs, before deciding that the patch has to delete every line of .vimrc and add every line of plugin/drupal.vim. (Am I wrong?)
I am leaving the status as "needs work" because I think it should be split up as described in #5.
Comment #9
kostajh CreditAttribution: kostajh commented@benjifisher Thanks for doing this, do you mind providing it as a tarball as well?
Comment #10
benjifisherNo problem, tar is much simpler than git.
Comment #11
kostajh CreditAttribution: kostajh commentedThanks! Maybe a project maintainer take the code from #10 and create a new branch that people could provide patches to? I also agree with the proposed structure in #5.
Comment #12
benjifisherHere is a better starting point. It implements the structure from #5. I leave out the syntax directory, and I name the ftplugin file to php_drupal.vim in case the user already has another ftplugin for php. Mostly I copied parts of the old .vimrc to the various files. For the ftplugin, I changed the :set commands to :setl and the mappings to use
<buffer>
and<LocalLeader>
. I made a few other changes here and there. (Ask if you see anything you do not like.)I tested by coping the tarball to my web server and
I resisted the temptation to add the patch from #1305564: Format comments, including documentation blocks., but I implemented #1303122-4: Syntax highlighting for .info and .make files.
Comment #13
skottler CreditAttribution: skottler commented@benjifisher: can you please also add a README.txt file to the tarball to explain what a user should do with the contains of the folder.
Comment #14
benjifisherHow about this for a start?
Comment #15
msonnabaum CreditAttribution: msonnabaum commentedI think this is the right way to go. I'm ok with this change happening in the main branch.
Comment #16
skottler CreditAttribution: skottler commentedComment #17
skottler CreditAttribution: skottler commentedSorry for the abrupt close. This has been committed.
Thanks very much @benjifisher!