A vim configuration for the PHP developer

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, February 18, 2012

Follow me on Twitter as @mattiasgeniar

I’m a fan of vim. I cursed at it for 2 years before I loved it, but I wouldn’t want any other editor anymore. However, I do require a few changes to the default behaviour of vim before it suits my needs when I’m doing PHP development.

Here’s my current ~/.vimrc file I use.

" Vim configuration file

" No more "vi" compatibility
set nocompatible

" General vim stuff
filetype plugin on
filetype indent on
syntax on
set nowrap

" Default color
colorscheme desert

" I don't want those .swp files cluttering up my normal directories
" Gets very messy with version control
" So store them in a seperate directory
set directory=~/.vim/swap-files,~/tmp,.

" VCL stuff, for editing Varnish files
au BufRead,BufNewFile *.vcl :set ft=vcl
au! Syntax vcl source ~/.vim/syntax/vcl.vim

" Parse the php-fpm.conf file as a dosini
autocmd BufRead,BufNewFile /etc/php-fpm.conf set syntax=dosini

" Show nice info in ruler
set ruler
set laststatus=2

" Set standard setting for PEAR coding standards
set tabstop=4
set shiftwidth=4
set expandtab

" Auto indenting is just so nice
set autoindent
set smartindent

" When searching in vim, make sure the search hit is never at the bottom
set scrolloff=5

" This setting hurts you the most when first starting with vim: disable the arrowkeys. For navigation, use "hjkl"
" You'll probably want to disable these when first using vim.
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
vnoremap <up> <nop>
vnoremap <down> <nop>
vnoremap <left> <nop>
vnoremap <right> <nop>

" Source/reload .vimrc after saving .vimrc
autocmd bufwritepost .vimrc source $MYVIMRC

" Increase the history buffer for undo'ing mistakes
set history=1000
set undolevels=1000

" Enable at least 256 colors instead of the default 8 (I think?)
set t_Co=256

I also using the Varnish VCL syntax highlighting plugin provided by Steven Merril.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.