Why on earth would any sane person use Vim for PHP development ? Is it still relevant in the days of full blown IDE's ?
Senior Webdeveloper - Studio Emma
Archlinux Trusted User
Vim user :-)
“Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems.”
“Vim is often called a "programmer's editor," and so useful for programming that many consider it an entire IDE. It's not just for programmers, though. Vim is perfect for all kinds of text editing, from composing email to editing configuration files.”
“Vim isn't an editor designed to hold its users' hands. It is a tool, the use of which must be learned.”
“Vim isn't a word processor. Although it can display text with various forms of highlighting and formatting, it isn't there to provide WYSIWYG editing of typeset documents. (It is great for editing TeX, though.)”
“Vim isn't a desktop environment. If you want integrated twitter, email, webbrowser, ircclient, ... use emacs.”
Vim has everything (or almost) a PHP developer needs.
We just need to unlock or find the “right” feature.
Once you know it it's FAST!
Wtf, modal editor?
A modal editor has different modes of operation.
In this mode everything you “type” is interpreted as a command you give.
This is what you are used to, start typing and you are adding text
This mode could be compared to selecting some text
To define a visual highlight you can use all movement keys
If you really want you can move around with your mouse and with your arrow keys
Wtf ? Commands, this is just a text editor, why don't you just let me type in some text
Quantifiers can be used to 'extend' the reach of a command
Most commands support ranges, ranges are defined like
“:help formatting” “:help text-objects”
If you are getting on a ubuntu server, first action:
apt-get install vim
In most linux distributions vim comes with syntax highlighting enabled by default.
In many distributions the default vim installed is a vi compatbile tiny version, install the full version!
The default search functions in Vim are fairly hard to use
We must explicitly add a configuration option to allow vim to load a .vimrc file from the directory you are starting vim from.
There is by default a file navigator built in in vim called netrw, if you have to use it, it does the job fine, but it is not really user frienly.
We can also easily navigate our files if we use tags.
The configuration will be done in “~/.vimrc” and addidional plugins to make our lives easier go into “~/.vim”
Vim has a vi compatible mode or you can choose to use the no compatible mode to be able to use all Vim specific features
Vim creates a backup of every file you edit, it also keeps a “swap” file by default. Vim also keeps views around but I personally never saw one saved to disk.
Vim can also persist undo information.
By default all these files are stored next to the file you are editing, this can pollute your source tree.
We have to enable syntax highlighting and filetype detection, most distributions already enable this by default.
Tabstop is going to define how the syntax indentation and tab key will behave.
When we are programming knowing what line we are on
And ofcourse we 'never' use the default colorscheme since we all think thatone is not good enough for us
The ones mentioned before are “most” important to do our job
What follows are a list of plugins I use, that does in no way mean those are the best. When you use a plugin make sure you feel an improvement in your workflow.
(C)tags is not really a plugin, it is a built in feature of Vim. This built in feature can already start making our lives much easier.
There are plugins to generate your tagfiles on save, or on quit. I personally generate them whenever I see fit.
In the old days you usually installed plugins by extracting a zipfile in your “~/.vim” folder. Luckily, these days are over, now we have several plugins ;) that manage our plugins.
Some “plugin managers”:
The NERD Tree is a tree like file explorer for vim
In short this is a fuzzy typed fast filefinder
As you could guess the plugin uses the ack command to search in code files.
NERDTree Ack is an extension for nerdtree which adds a few menu items to search with ack
Sauce is a “project” like plugin, it creates an extra project specific vimrc file where you can keep the location of the project, maybe indenting options, ...
VIM bufferlist gives you a list of open buffers (files).
Supertab is a plugin that helps you to use completion in insert mode, when you press
Syntastic is a syntax checker plugin, it will run a syntax check on the open file.
Tagbar displays a summary of your class or file. It lists classes, paramters and methods.
NERDcommenter helps you to quickly add comments to a line or multiple lines.
PHP Documentor for Vim is a plugin to easily create docblocks on your classes, parameters and methods.
php_getset creates getter and setter methods from the paramters selected in your class.
Fugitive is a git wrapper for vim, you can run practically every git command from fugitive.
Vdebug is a debugger for Vim. Every debugger speaking DBGP protocol can be used. Xdebug speaks DBGP ;)