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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kostajh’s picture

extract the project to ~/.vim/drupalrc, add source ~/.vim/drupalrc/vimrc to ~/.vimrc" or similar.

That makes sense, good suggestion!

skottler’s picture

I 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.

skottler’s picture

Status: Active » Needs work
benjifisher’s picture

Do 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.

:help plugin
:help ftplugins
:help after-directory " under "help 'runtimepath'
:help new-filetype
benjifisher’s picture

I 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.)

vimrc/plugin/drupal.vim
vimrc/ftdetect/drupal.vim
vimrc/ftplugin/php.vim
vimrc/doc/drupal.txt
vimrc/syntax/php.vim
  • Global settings and some autocommands (those that highlight trailing whitespace, for example) go in plugin/drupal.vim, as well as the :filetype and :syntax commands.
  • The autocommands that recognize PHP files go in ftdetect/drupal.vim.
  • The settings that should be defined for each file you edit go in ftplugin/php.vim.
  • The vim help files go in the doc directory, and the syntax commands go in the syntax directory. (Edit: I originally wrote drupal.vim instead of drupal.txt for the vim help file.)

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 of drupal.vim.

:help vimfiles
:help add-global-plugin
:help ftdetect
:help add-filetype-plugin
:help add-local-help
:help :syn-files
skottler’s picture

@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?

benjifisher’s picture

So just replace vimrc/.vimrc with vimrc/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.

:help credits
/Benji Fisher
benjifisher’s picture

Here 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.

kostajh’s picture

@benjifisher Thanks for doing this, do you mind providing it as a tarball as well?

benjifisher’s picture

FileSize
1.95 KB

No problem, tar is much simpler than git.

kostajh’s picture

Thanks! 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.

benjifisher’s picture

Status: Needs work » Needs review
FileSize
2.23 KB

Here 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

$ tar xzf src/ultimate_vimrc.tgz 
$ mv vimrc/* .vim

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.

skottler’s picture

@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.

benjifisher’s picture

FileSize
2.76 KB

How about this for a start?

		 Vim configuration files for Drupal developers

The files in this directory are designed to make it easier for Drupal developers to edit files using vim.

INSTALLATION

Copy the files, other than this README.txt, into your vimfiles directory.  For most users, your vimfiles directory is ~/.vim; from within vim, use

:help vimfiles

for details.  If you have downloaded these files as ultimate_vimrc.tgz and your vimfiles directory is ~/.vim, then this should work:

$ cd ~/.vim
$ tar xzf ~/src/ultimate_vimrc.tgz --strip-components 1
$ rm README.txt

When you are done, you should have the following directory structure inside your vimfiles directory:

	doc/
	ftdetect/
	ftdetect/drupal.vim
	ftplugin/
	ftplugin/php_drupal.vim
	plugin/
	plugin/drupal.vim

UPDATES AND SUPPORT

For the latest version of this project, see http://drupal.org/project/vimrc .
To file a bug report or feature request, see the corresponding issues queue:
http://drupal.org/project/issues/vimrc?status=All&categories=All
msonnabaum’s picture

Status: Needs review » Reviewed & tested by the community

I think this is the right way to go. I'm ok with this change happening in the main branch.

skottler’s picture

Status: Reviewed & tested by the community » Closed (fixed)
skottler’s picture

Sorry for the abrupt close. This has been committed.

Thanks very much @benjifisher!