Drupal/Vim users, highlight your .module files

I live in Vim, but finally got tired of editing my .module files without syntax highlighting - ugh. Turns out all you have to do is tell vim what the file is so that it knows what to shade.

Make sure that the following is in your vimrc file - notice the filetype on line:

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
filetype on
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

Then place the following in ~/.vim/filetype.vim, restart Vim and you are all set!

"  ~/.vim/filetype.vim
" tell Vim what a .module file is
if exists("did_load_filetypes")
  finish
endif
augroup filetypedetect
  au! BufRead,BufNewFile *.module               setfiletype php
augroup END

See also!

Hi Kevin!

For more great vim things, I think also the simpler way to do this, see also

http://phpslacker.com/2009/02/05/vim-tips-for-php-programmers/

and Drupal.org's own Configuring vim.

Meantime I try to keep Vim as PHP IDE and another page on vim configuration up to date with code and links on agaric...

benjamin, Agaric

More files ...

I have had this config in ~/.vim/filetype.vim for a long time:

It handles all Drupal file types that are essentially PHP or similar.

" File types
if exists("did_load_filetypes")
  finish
endif
augroup filetypedetect
  au! BufRead,BufNewFile *.php,*.module,*.theme,*.inc,*.install,*.info,*.engine,*.profile,*.test setfiletype php
augroup END

For gvim I use filetype plugin on

That way, I can get support for a variety of languages.

Here is my .vimrc (for ruby, python and php):

set expandtab
set tabstop=2 shiftwidth=2 softtabstop=2
set autoindent
set nocompatible

syntax on
filetype on
filetype indent on
filetype plugin on

autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class

if has("autocmd")
augroup php
autocmd BufRead *.inc set filetype=php
autocmd BufRead *.module set filetype=php
augroup END
endif

I also have a module.vim and a php.vim in $HOME/.vim/after/ftplugin

module.vim:

:colo sea

set expandtab
set tabstop=2 shiftwidth=2 softtabstop=2
set autoindent

set foldmethod=indent
set filetype=php

php.vim:

:colo sea

set expandtab
set tabstop=2 shiftwidth=2 softtabstop=2
set autoindent

set foldmethod=indent

(got the colorschemes *.vim files installed in $HOME/vim/colors)

Victor Kane
http://awebfactory.com.ar

This is what I use and works

This is what I use and works well enough:

~ Singh$ cat .vimrc

au BufRead,BufNewFile *.module set filetype=php
syntax on

--
Gurpartap Singh -- http://gurpartap.com

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <a>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.
My name is Kevin. I am a software engineer and bike geek living in Salem, Mass. I use Vim even when I don't need to. When I'm not on the computer, I'm usually hanging with my wife, Melissa and baby Benjamin or working on my pet project BIKENE.WS.