vim editor for Drupal developers

I have been looking recently at using vim for Drupal development and as well as to do web development in general. I used to use Eclipe PDT but when you work on big project it can be slow. I have been using vim for some time as I am Linux user. I did not know that this is such a powerful tool - I used only what comes with default installation of vim and did not spend much of my time to learn about additional options. Core functionality of vim can be extended by installing plugins or scripts - search Internet and you can find quite large number of projects.
This document should be treated only as a general introduction not as complete document about vim. Where it is more appropriate I give just short explanation and provide links to external resources that I found useful and that provide more information. I recommend to check provided links for more detailed information.

vim brief introduction

The vim text editor is very powerful tool that can be used in text as well as graphical environment. It is based on vi text editor. If you are already Linux user you are probably using this text editor most likely to amend configuration files.

For more information about vim please check below link - there are links I use:

  1. http://www.vim.org - this is main website where you can find more information about Vim project.
  2. http://vimdoc.sourceforge.net - vim online user documentation (manuals in various formats, you can as well download book in PDF format for free).
  3. http://www.vim.org/community.php - in case you need help the best place is to look for help within online community.
  4. http://vim.wikia.com/wiki/Vim_Tips_Wiki - WIKIBook, visit it and search for tips and tricks.
  5. http://en.wikibooks.org/wiki/Learning_the_vi_Editor/Vim - vim online tutorial.
  6. http://vim.runpaint.org/ - vim recipes.
  7. http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.html

Above links should allow you to find/learn about general use of vim - If you new or want to learn new tricks. In the remaining part of this document I am going to write more about specific steps to configure vim to support Drupal development.

Like with all the new tools there is a learning curve involved but to make it easier you may start using graphical version of vim called Gvim - most of the options you can find from menu (keyboard shortcuts provided for your convenience).

Steps to install vim on Ubuntu:

In case you do not have vim installed below are commands that allow you to install it on Ubuntu/Debian:

sudo apt-get update
# installing console version of vim
sudo apt-get install vim
# installing GUI based vim
sudo apt-get install vim-gnome

Vim can be configured to do things in the way you want by amending .vimrc file that is stored in your home directory (~) - in case it doesn't exisit you can create one. In the directory /usr/share/vim/vim73 you can find more default files that comes with vim - e.g. color schemes, detect file types or highlight syntax for various languages such as PHP, JavaScript, CSS, HTML, C and more.

Setting up vim for Drupal developers:

When I was reading how to set up vim for Drupal developers I found below pages very useful:

You should refer to above links for detailed information. I will show steps I did to set up vim on my Ubuntu machine:

  1. Requirements

Before you go to next steps make sure that vim and drush is available on your system - if you do not have them please install them now. In most cases you would be able to install it from Ubuntu/Debian repository.

  1. Instruction to install vim configuration files for Drupal developers
drush @none dl vimrc
drush -v vimrc-install

After running above command you can find:

  • ~/.drush/vimrc - drush downloads to this directory vim configuration files for Drupal development, for more information please read README.txt
  • ~/.vim/ - in this folder we have some additional plugins that are installed by default (requires drush version 5.5+), we can add more if we need here in the future. These plugins here are general one not tailored to Drupal development.

In during this step drush adds instruction to user's vim configuration file ~/.vimrc - in order to include script/plugins from above locations (~/.drush/vimrc/bundle and ~/.vim/bundle). At this moment vim is configured to enhance Drupal/web development on our machine.

  1. Edit .vimrc to add some more settings

Above is what I added to my .vimrc file:

" I  use vim configuration file that comes with vimrc project
source ~/.drush/vimrc/examples/vimrc_timplunkett.vim

" Below lines are for general vim settings
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set smartindent

syntax on
" changed default colorschema to elflord
" additional colorschame check /usr/share/vim/vim73/colors
" or search Internet, download and enable
colorscheme elflord
  1. To test that vim now provides support for Drupal developers, browse to your Drupal project (vim would detect version of Drupal, as well type of file you edit and uses correct setting) and edit file and try things that are on this vimrc project page as well as this documentation page.

Summary:

By installing vimrc project from drupal.org we can configure vim quickly to support Drupal development. This project brings together vim configuration files as well as recommended vim plugins that once installed allow us to develop faster, easier as well as to create higher quality code for Drupal projects - as well as for PHP web application, HTML, JavaScript or style files.

In nutshall we: installed vim, amended user's vim configuration file, downloaded additional plugins that extend default functionality of vim - and we did this typing just two command in the terminal.

This is just a starting point - more you develop more additional plugins and scripts you may want to install to be able to develop faster and spend more time on writing more efficient and elegant code.

In my next article I am going to provide some more explanation of components that we have installedhow as well as show examples how to use installed vim plugins.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.