My Vim configuration on GitHub.com
Since i have done a few blogposts (1, 2) about my Vim installation, I think it’s about time i show you guys my configuration.
I'm living in Copenhagen with my wife and Dogs.
Drupal developer for a living.
Since i have done a few blogposts (1, 2) about my Vim installation, I think it’s about time i show you guys my configuration.
I have been using the Syntastic plugin for vim for a long time. Syntastic does what it have to, in php files it validates the file by in short terms do a
$ php -l FILENAME
And present the error(s) in the statusbar, and with a little marker at the line(s).
If you install the PHP_CodeSniffer via the pear installer, Syntastic automatic validates the code against the default code standards setup in php_codesniffer.
I found DrupalCS module by Ericduran which is a PHP code sniffer addon, and tests your active code on-the-fly when saving.
The DrupalCS and phpcs (php code sniffer) is integrated into the Syntastic plugin.

The installation of PHP Code Sniffer and Drupal CS is quite simple, and it’s nicely documented on the DrupalCS module page.
After installing it, you can test if the DrupalCodingStandard work by test if it’s loaded in your terminal
$ phpcs -i
If you want to test a file from your terminal, you can fire the command
phpcs --standard=DrupalCodingStandard --extensions=php,module,inc,install,test,profile,theme FILENAME.module
The result will look something like this output
If you execute the phpcs without the Drupal specific validator
$ phpcs --extensions=php,module,inc,install,test,profile,theme FILENAME.module
The result output is a bit more scary.
The configuration for vim im using to get it working is.
let g:syntastic_enable_signs=1 " Enable markers on the line containing a problem.
let g:syntastic_auto_jump=0 " Dont jump to the first line with a problem
let g:syntastic_phpcs_conf='--standard=DrupalCodingStandard --extensions=php,module,inc,install,test,profile,theme' " Test php,module,inc,install ... files with the DrupalCodingStandard
The first days after using it on a daily basis, it was quite annoying, but it have made me more aware of how i code.
My primary editor for PHP/Drupal programming have been MacVim for years, and therefore my editor have been tweaked and customized to my needs, you can see my .vimrc file. I’m always ready for new plugins, new branches of existing repositories and to learn new.
The installed version of my MacVim is the snapshot-64. Which is installed with Homebrew.
First of all the colorscheme is very important, since we’re looking at it for (way too many) hours a day. I toggles between github and Mustang2.
Below theres a list of all the installed plugins im using these days. All plugins, syntax and colorschemes is handled by pathogen.vim which in short terms makes it very easy to install new plugins, colorshemes and so on.
Ack is an alternative grep command, which is more effective and fast. Use this plugin to search recursivly from the current path for a text-string.
:Ack 'function hook_node_info'
Will look in current path for the written text string.
CTRLP.vim is described in this blogpost.
Gundo.vim gives you a little window, where you will se a visualized view of your undo-tree.
Jsbeautifier is a little tool, which can format / indent your .js code nice, an online version can be found here jsbeautifier
JSHint is a little nodeJS tool, so you can test your .js code for code errors.
:JSHint %
Will run jshint on the current file and open a little scratch window, which describes all errors with linenumbers.

NERDCommenter provides a nifty feature to easy change a block of text to a comment block, supports a lot of different filetypes.
NERDTree have been the most important plugin for me, the plugin creates a window where you can explore your filesystem, open files and create/delete files/directories.

Syntax highlight file for php5, which can be configured a bit.
Supertab works when hitting <TAB> when typing a word, it will display a box with text suggestions, and you can browse through suggestions with <TAB> and <S-TAB>

Syntastic checks your sourcecode for syntax errors. It checks your code through external syntax checkers. You will be notified by a little mark on all lines containing an error. And shows a window where information about the error is shown.
Check this blogpost for a lot more info on this subject.
Tagbar shows a sidebar with functions, variable definitions generated by ctags. Classes, properties, methods and functions in javascript.

vim-buffergator lets you see a window on the left, with all open buffers.
vim-css-color will highlights color definitions in css-files. a color will be shown with the color as background for the text, #f00 will be shows as white text on red background.
Vim-fugitive Handle various git commands from within vim.
Vim-indexed-search shows a “Match x of y” when searching in buffers.

Vim-jquery is a syntax file to add some colorations for jQuery keywords and css selectors.
Vim-matchit - The % in normal vi/vim will jump between matching [ ( {’s, with matchit you will be able to jump between keywords as if, then, else, foreach, you can decide yourself, the configuration goes into the .vimrc file.
Vim-nginx is as simple as syntax colors for nginx configuration files.
Powerline is a utility plugin which allows you to create better-looking, more functional vim statuslines.
Vim-surround is all about “surroundings”: parentheses, brackets, quotes, XML tags, and more. The plugin provides mappings to easily delete, change and add such surroundings in pairs
ZoomWin you easy makes your window zoom in/out of full screen with
A fuzzy file, tag, recently used files finder plugin for the vim editor, which makes my day so more easy.
I use to use the Command-T plugin, but found CTRLP.vim on The Changelog. The Command-T plugin is a quite more simple than CTRLP.vim, and needs ruby to be installed. But the major reason for changing is that CTRLP.vim is more advanced, and the features is
Endless (Taken with instagram)
Homebrew - as told on the website, The missing package manager for OSX, it’s the easiest and most flexisble way to install various tools Apple didn’t include with OSX. The HomebrewAlt is an addon to the normal homebrew, with a lot of new apps to install. We’re using it to get php upgraded to 5.3.8.
There are a few requirements to be able to install Homebrew, and it’s:
It’s pretty simple to install Homebrew, it’s done with this oneliner.
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
If you want to see the script.
Homebrew it now installed in /usr/local and it’s path is writeable by the user who have installed it, so you can acutally install with homebrew without sudo’ing.
Download and install Homebrew-alt into /usr/local/LibraryAlt
git clone https://github.com/adamv/homebrew-alt.git /usr/local/LibraryAlt
Add /usr/local/bin and /usr/local/sbin to your path.
vim ~/.zshrc
Paste the following into the very buttom of the file and [esc]:wq
export PATH=$(brew --prefix)/bin:$(brew --prefix)/sbin:$PATH;
Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
It’s simply installed with
brew install git
And you’re good to go.
iTerm2 is a replacement for Terminal. iTerm2 has a rich collection of features.
Go to www.iterm2.com and download and install the app.
The ZSH is a shell designed for interactive use, although it is also a powerful scripting language, it will be installed along with [oh-my-zsh)[https://github.com/robbyrussell/oh-my-zsh] which is a framework for managing your ZSH configuration, theres a lot of plugins, which adds tab-completion for ex, git homebrew, and a lot of terminal themes to spice it all up with.
First we need to install wget and a never version of zsh, to download and execute the oh-my-zsg install script, it’s so easy done with homebrew.
brew install wget zsh
Fire this command to install oh-my-zsh
wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
To get Macvim installed we again simply use Homebrew, we add a little something to homebrew, to learn a new sub command.
We want to search the homebrew library to see if MacVim is available to install.
brew search macvim
And we’re getting:
$ brew search macvim
macvim
Which means that it’s available, and ready for installation
brew install macvim
You can now start MacVim from your terminal with
mvim FILE
named is a domain name daemon, which can act as a local dns server.
We need to set up named (bind), to handle wildcard DNS for our development TLF (top level domain) and using OpenDNS as secondary DNS lookup for all other requests.
Everything is set up in your terminal as root user.
sudo -i
To be sure, backup the original configuration
cp /etc/named.conf /etc/named.conf.orig
Create a keyfile which is read by named on startup.
rndc-confgen -a
Edit the named.conf file
vim /etc/named.conf
Somewhere inside options {} block, add OpenDNS as DNS forwarder.
forwarders {
208.67.222.222 // OpenDNS primary
208.67.220.220 // OpenDNS secondary
}
Add the following before the “0.0.127.in-addr.arpa” IN { zone
zone "dev" IN {
type master;
file "dev.zone";
};
Save your named.conf file [esc]:wq
Now we need to create the dev.zone file, so bind (named) could read the dns configuration for that tld.
vim /var/named/dev.zone
And paste this block into that file.
dev. 7200 IN SOA dev. root.dev. (
2008031801 ; Serial
15 ; Refresh every 15 minutes
3600 ; Retry every hour
3000000 ; Expire after a month+
86400 ) ; Minimum ttl of 1 day
IN NS dev.
IN MX 10 dev.
IN A 127.0.0.1
*.dev. IN A 127.0.0.1
Save the file, agagin, with [esc]:wq
Run the following commands to ensure configuration is ok
named-checkconf /etc/named.conf
And
named-checkzone dev /var/named/dev.zone
Now set your computer dns to use localhost as primary dns handler, in System Preferences -> Network for both Wireless and Ethernet connections by clicking Advanced and selecting the DNS tab, and add 127.0.0.1.
Set Bind (named) to load when computer starts, and load it now.
launchctl load -w /System/Library/LaunchDaemons/org.isc.named.plist
Let’s flush the internal DNS cache first,
sudo dscacheutil -flushcache
Lets test that everything is working as planned.
dig test.dev
Should return something like
$ dig test.dev
; <<>> DiG 9.7.3-P3 <<>> test.dev
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4384
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;test.dev. IN A
;; ANSWER SECTION:
test.dev. 7200 IN A 127.0.0.1
;; AUTHORITY SECTION:
dev. 7200 IN NS dev.
;; ADDITIONAL SECTION:
dev. 7200 IN A 127.0.0.1
;; Query time: 2 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sun Dec 18 10:51:34 2011
;; MSG SIZE rcvd: 72
And we can see it’s resolved as a local domain. All ok.
And a ping test, should return
$ ping test.dev
PING test.dev (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.041 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.110 ms
Nginx is an awesome alternative to Apache Web Server, more lightweight, very customizable, and thats for good use with this setup.
This Nginx vhost configuration is mostly for Drupal installations, but works with other frameworks and homemade stuff, almost out-of-the-box, but changes to the vhost.conf file, depending on configration in your .htaccess file used in Apache, can appear.
First of all we need to ensure that Apache wont be started when booting.
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
Now we need nginx to be installed via Homebrew.
brew install nginx
When nginx is compiled, we need to backup the original nginx.conf file.
cp /usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/nginx.conf.orig
Open and configure your nginx.conf file to your needs.
vim /usr/local/etc/nginx/nginx.conf
Look for user in the file, and make it look like
user YOUR_NAME staff;
Save the file [esc]:wq
Create the nginx log directory, to make it show up in Console.app
sudo mkdir /var/log/nginx
Edit your nginx.conf
vim /usr/local/etc/nginx/nginx.conf
And add the following line in the http {} section just before the closing }
include /usr/local/etc/nginx/vhosts.conf
Save and exit the file [esc]:wq
Create the vhosts.conf file, in this example it’s confiugred for drupal development, but will work for the most.
vim /usr/local/etc/nginx/vhosts.conf
And paste the following into the file.
server {
listen 80 default;
server_name _;
index index.php;
if ($host ~* "^(.+)+.dev$") {
set $site $1;
}
root /Users/[USERNAME]/www/$site;
access_log /var/log/nginx/$host.access.log combined;
error_log /var/log/nginx/$host.error.log crit;
add_header X-Frame-Options SAMEORIGIN;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location = /backup {
deny all;
}
location ~ \..*/.*\.php$ {
return 403;
}
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}
location ~ \.php$ {
fastcgi_read_timeout 600;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
# Fighting with ImageCache? This little gem is amazing.
location ~ ^/sites/.*/files/styles/ {
try_files $uri $uri/ @rewrite;
}
}
Create a www folder in your homedir
mkdir ~/www
Restart your nginx
sudo nginx -s reload
And now you should be able to create new local sites without configurering and restarting nginx everytime.
The version of PHP in OSX Lion is upgraded to 5.3.6, but we will install PHP 5.3.8 with Homebrew, and with that it would be upgradeable, when new and awesome releases appear.
Now for the PHP 5.3.6 -> 5.3.8 upgrade. We will start by backing up the originally installed php.
sudo mv /usr/bin/php /usr/bin/php.orig
Run homebrew installer with the php brew file from the alternative brew directory.
brew install /usr/local/LibraryAlt/duplicates/php.rb --with-mysql --with-fpm
When php is compiled and ready, create your own php-fpm.conf file.
cp /usr/local/Cellar/php/5.3.8/etc/php-fpm.conf.default /usr/local/Cellar/php/5.3.8/etc/php-fpm.conf
Create symbolic link for it in /usr/local/etc/
sudo ln -s /usr/local/Cellar/php/5.3.8/etc/php-fpm.conf /usr/local/etc/php-fpm.conf
Edit the file
vim /usr/local/etc/php-fpm.conf
Add the following line below ;pid = run/php-fpm.pid
pid = /usr/local/var/run/php-fpm.pid
Update the user and group section as follows
user = _www
group = _www
Remove the ; from the start of the following lines then save using Ctrl+X then Y
pm.start_servers = 3
pm.min_spare_servers = 3
pm.max_spare_servers = 5
pm.max_requests = 500
Create directory for php-fpm log
mkdir /usr/local/Cellar/php/5.3.8/var/log/
and the file
touch /usr/local/Cellar/php/5.3.8/var/log/php-fpm.log
Make our log file visible in Console app
sudo ln -s /usr/local/Cellar/php/5.3.8/var/log/php-fpm.log /var/log/nginx/php-fpm.log
Set your timezone in php.ini
vim /usr/local/etc/php.ini
Look for ;date.timezone, and add following below
date.timezone = Europe/Copenhagen
And update the memory_limit
memory_limit = 256M
Save the file [esc]:wq
MariaDB is an alternative to MySQL, it’s created and maintained by some original authors of MySQL.
Install MariaDB from terminal and with homebrew
brew install mariadb
After installation is done, unset TMPDIR
unset TPMDIR
Then install database
mysql_install_db
Start iterm2 and become root.
sudo -i
Download the LaunchDaemon to load nginx on boot
curl http://realityloop.com/sites/realityloop.com/files/uploads/nginx.plist_.txt > /System/Library/LaunchDaemons/org.homebrew.nginx.plist
Download LaunchDaemon for php-fpm
curl http://realityloop.com/sites/realityloop.com/files/uploads/php-fpm.plist_.txt > /System/Library/LaunchDaemons/org.homebrew.php-fpm.plist
Copy the LaunchDaemon to load MariaDB on boot into place
cp /usr/local/Cellar/mariadb/5.2.8/com.mysql.mysqld.plist /System/Library/LaunchDaemons/com.mysql.mysqld.plist
Now it’s time to reboot your computer, to make sure everything is working.
After reboot, open iterm and run this command.
sudo /usr/local/Cellar/mariadb/5.2.8/bin/mysql_secure_installation
Answer the prompts as follows, replace [password] with a password of your own chosing
Enter current password for root (enter for none): [Enter]
Set root password? [Y/n] y
New password: [password]
Re-enter new password: [password]
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
Now for an example by installing a drupal site with a few tools.
Download drush which is a command line tool for Drupal, this will install drush_make as well.
brew install drush
Go to ~/www
cd ~/www
And download Drupal core.
drush dl drupal --drupal-project-rename=drupal7
Open your favorite browser and go to
http://drupal7.dev
You should see the installation page of Drupal. We could install drupal with a oneliner.
cd ~/www/drupal7
And we use drush to install with default settings.
drush site-install --db-url=mysql://root:PASSWORD@localhost/drupal7
And if you visit
http://drupal7.dev
you will see a default installed drupal site, and you will be able to login with user: admin, pass: admin.
We’ll just try another site
cd ~/www/
Install a drupal 6.x site
drush dl drupal-6.x --drupal-project-rename=drupal6
And again use drush site-install to install the site.
drush site-install --db-url=mysql://root:PASSWORD@localhost/drupal6
And visit
http://drupal6.dev
You will see an installed drupal 6 site.
** And everything without reloading Nginx ** - MAGIC
As a little note, it would quite easy install on a unix based platform as well, skip the homebrew parts and install through your preferred install util (apt-get or whatever).
The paths would in most cases deviate a bit from the ones on OSX.
I just tested it on a Ubuntu 10.04, and took me around 10 mins to install from this guide.
Was tired of doing a
Every time i have to know which version is installed of a drupal module or theme. So i made a (very beta) little custom drush command, which shows some info about the chosen module.
Outputs
Download
https://gist.github.com/1354686
Installation
See comment in the file.
In the Alfred.App 0.9 release it’s now possible to execute shell commands (Thank you).
For that i have made a few custom commands which makes my day a lot easier.
The most important for now is my Lorem Ipsum fetcher. Which i can execute by accessing Alfred.App and type “lorem” + [Enter] - and a random lorem ipsum paragraph is sent to my clipboard.
The command is:
curl --silent http://loripsum.net/api/1/medium | pbcopyAnd remember to tick the ‘silent’ then it should be all good.
F.lux makes the color of your computer’s display adapt to the time of day, warm at night and like sunlight during the day.
Vagrant is a tool for building and distributing virtualized development environments.
By providing automated creation and provisioning of virtual machines using Oracle’s VirtualBox, Vagrant provides the tools to create and configure lightweight, reproducible, and portable virtual environments.