Other features
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
On this page:
- Tag searches
- Open documentation in a web browser
- Other mappings
- Drush integration
- Support for the Coder module
The Vimrc Project
This page is part of the documentation for the vimrc project. For other documentation pages, check the links in the sidebar or go to the top documentation page.
Tag searches
Tags files are usually created by an external program, such as Exuberant ctags. See :help 29.1
in the vim users' manual, or :help tagsrch
in the reference manual, for an introduction to using tags. You can also explore the options from the Drupal.Tags menu if you are using a GUI version of vim.
The vimrc project includes a tags file for Drupal core. In fact, it includes several: as of early 2012, there are separate tag files for Drupal versions 6, 7, and 8. For example, you can use
:stag drupal_set_message
or
:stag /set_mess
to jump to the definition of drupal_set_message()
in includes/bootstrap.inc
in a new window. If the cursor is on the text drupal_set_message
, then you can also use <C-W>]
.
If you want to abandon the file you are currently editing and use the current window, use :tag
instead of :stag
or <C-]>
instead of <C-W>]
.
For this to work, vim must be able to find your Drupal code base. This will be automatic if you are editing a file anywhere in the directory tree under your Drupal root. In order to see what vim thinks your Drupal root is, use
:echo b:Drupal_info['DRUPAL_ROOT']
For now, the tag files do not include tags for Drupal hooks. See the next section for an alternative.
If Exuberant ctags is available, then you can create custom tags files using the included drush command. See $ drush help vimrc-tag-gen
or :Drush help vimrc-tag-gen
for details, or use the Drupal.Tags menu.
Open documentation in a web browser
If you would rather read documentation in a web browser than in vim, you can use the following commands:
- \da
- Open a web browser on the http://api.drupal.org page for the function under the cursor.
- \dh
- Open a web browser on the http://api.drupal.org page for the hook implemented by the function under the cursor.
- \dda
- Open a web browser on the http://api.drush.ws page for the drush function under the cursor.
For Drupal functions, you should get the correct version of the function under the cursor. To see what version of Drupal vim thinks you are using, type
:echo b:Drupal_info['CORE']
Drush integration
Drush is the preferred tool for installing this project. See the Installation page.
If drush is installed, then the command :Drush <subcommand>
will execute the subcommand using drush and save the output in a scratch buffer. This only works for non-interactive commands; you can use the --yes or --no drush flags if you are sure. Subcommands and site aliases (start with '@') are completed intelligently. Examples:
:Drush help
" Compare installed packages on local and stage:
:Drush @local pml
:diffthis
:Drush @stage pml
:diffthis
" Living dangerously:
:Drush --yes rsync @stage:%files @local:%files
See also Tag searches above.
Other mappings
- \dv
- Get the value of the drupal variable under the cursor. (requires drush)
Support for the Coder module
We recommend the Syntastic plugin to highlight syntax errors and violations of coding standards. The Coder module will automatically correct some of these errors and violations. Once you have installed and enabled the Coder module, you can invoke it from within Vim:
:compiler coder
:make %
:e!
:diffsplit %.coder.orig
These four lines will
- set the :compiler plugin to use the PHP script included with the Coder module;
- invoke the Coder script, replacing your file with the corrected one;
- re-load the file into vim;
- open the original file in a split window using Vim's diff mode.
See :help 08.7 in the users' manual for an introduction to Vim's diff mode. See :help 30.1 for an introduction to using Vim's quickfix mode, :help quickfix.txt for complete details.
You can also run the Coder script on other files or entire directories. After setting the compiler plugin, try
:make another_file.php
:make includes/myfile.inc
:make includes/
:make .
:make %:p:h
(The last two run the Coder script on vim's working directory and on the directory of the current file, respectively.)
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion