Why on earth would any sane person use Vim for PHP development ? Is it still relevant in the days of full blown IDE's ?
“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.)”
The editor, what is it about
Hu ? 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
In the end you should move around without mouse or arrow keys
Why? Commands! This is just a text editor, why don't you just let me write some text.
“:help editing.txt”
“:help change.txt”
“:help change.txt”
“:help undo.txt”
Quantifiers can be used to 'extend' the reach of a command
Most commands support ranges, ranges are defined like
“:{start},{end} {command}”
“:help range”
“:help formatting” “:help text-objects”
Vim has it's own programming language VimL.
But not limited to it, you can use python, ruby, perl and lua too.
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 start doing our job
1 " nocompatible must be first ( use the real vimpower ) 2 set nocompatible
4 " backup rules 5 set backup " enable backup files (.txt~) 6 set undofile " enable persistent undo 7 8 silent execute '!mkdir -p $HOME/.vim/tmp/backup' 9 set backupdir=$HOME/.vim/tmp/backup " where to store backup 10 silent execute '!mkdir -p $HOME/.vim/tmp/swap' 11 set directory=$HOME/.vim/tmp/swap " where to store swap 12 silent execute '!mkdir -p $HOME/.vim/tmp/views' 13 set viewdir=$HOME/.vim/tmp/views " where to store view 14 silent execute '!mkdir -p $HOME/.vim/tmp/undo' 15 set undodir=$HOME/.vim/tmp/undo " where to store undo
17 " syntax 18 syntax on " enable syntax highlighting 19 " filetype 20 filetype on " enable filetype detection 21 filetype plugin on " enable filetype plugins 22 filetype indent on " enable filetype indentation
24 " tabstop settings 25 set tabstop=4 " a tab will be represented with 4 columns 26 set softtabstop=4 " <tab> is pressed in insert mode 4 columns 27 set shiftwidth=4 " indentation is 4 columns 28 set noexpandtab " tabs are tabs, do not replace with spaces
30 " show linenumbers 31 set number
33 " colorscheme 34 set background=dark " indicate we'll use dark background 35 colorscheme elflord " example colorscheme, is default available, many more can be added
Supertab is a plugin that makes completion 'super' easy.
(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.
“:help tagsrch.txt”
The default search functions in Vim are fairly hard to use
In short this is a fuzzy typed fast filefinder
As you could guess the plugin uses the ack command to search in code files.
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 NERD Tree is a tree like file explorer for vim
NERDTree Ack is an extension for nerdtree which adds a few menu items to search with ack
You could manually abuse the makeprg setting in vim and set it to “php -l %” but when using PHP, html, javascript, ... you might want syntax errors for all of those languages.
Syntastic is a syntax checker plugin, it will run a syntax check on the open file.
We must explicitly add a configuration option to allow vim to load a .vimrc file from the directory you are starting vim from.
“:help exrc”
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, ...
These days we are so used to vcs integration we also depend on it inside our editor/ide
Fugitive is a git wrapper for vim, you can run practically every git command from fugitive.
Signify is a plugin to indicate what lines are removed/added/changed. It supports multiple vcs systems.
Debugging for specific languages is not built into vim because there are many protocols and systems to support.
Vdebug is a debug integration for Vim. Every debugger speaking DBGP protocol can be used. Xdebug uses DBGP ;)
For php there are a number of usefull plugins to make our lives easier
NERDcommenter helps you to quickly add comments to a line or multiple lines.
With UltiSnips you can create any possible snippet of code you want to reuse often
But why recreate default templates when there is a central repository for those
php_getset creates getter and setter methods from the paramters selected in your class.
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”:
@BlackIkeEagle
Senior Webdeveloper - Studio Emma
PHP-WVL
Archlinux Trusted User