Vim IDE and PHP / Symfony / Web develompment

VIM is very useful feature reach development environment. Its look & feel is beet different than other well known IDE. This difference is VIM power – it is extremely fast, has syntax highlighting, auto indent, bracket matching, code folding, etc.

VIM Logo VIM is very useful feature reach development environment. Its look & feel is beet different than other well known IDE. This difference is VIM power – it is extremely fast, has syntax highlighting, auto indent, bracket matching, code folding, etc.

VIM can work as the fastest professional development environment but requires from user change some of his habits. For the convenience of working with VIM you will need few free lessons (from vimtutor) a bit time and tips from this blog. After all you will work the most efficiently with the VIM, faster than in any other editor.

[ad#Inside post ad]

Basics
As I wrote earlier at first you should learn a few lessons which includes tutorial. You will easily work with VIM after that. To take the tutorial, run following commands.

aptitude install vim
vimtutor

Setup IDE
The basic version of Vim is not suitable for work as an IDE. Comfortable work with it will be possible after adding a few plugins and set the appropriate options.

I have installed some plug-ins and keyboard shortcuts on my .vimrc file. I am using these settings later in this article. To install them run in console:

sudo aptitude install exuberant-ctags
cd ~
wget http://rafal.zelazko.info/wp-content/uploads/ftp/vim-custom.tgz
tar -xvzf vim-custom.tgz -C ~
rm vim-custom.tgz

Keyboard shortcuts info
In this post I am using the following notation of keyboard shortcuts:
c-x means that you must press both “Ctrl” and “x”
c-x c-o means that you must press both “Ctrl” and “x”, release them and press both “Ctrl” and “o”

My VIM settings and plugins
There are some interesting features in my .vimrc file:

  • esc c capitalize current word
  • esc l lowercase current word
  • esc u uppercase current word
  • Word completion on tab
  • Duplicate line c-d
  • Show file tree f7
  • Change file encoding to ISO-8859-2 (without converting) esc _i
  • Change file encoding to UTF-8 (without converting) esc _u
  • Paste text from buffer without broken indent: f11 shift-insert f11

Tabs, windows, screens
VIM Splited vertically
Keyboard shortcuts related to manipulate window, tabs and screens:
New tab: :tabe /path/to/file
Jump between tabs gt and gT
List opened tabs along with windows/buffers they contain :tabs
Close the active tab :tabc
Split screen horizontally :split /sciezka/do/pliku
Split screen vertically :vsplit /sciezka/do/pliku
Jump between screens: c-w arrow

Code completion
Completion of function names: tab or c-x c-o
File completion: c-x c-f
Line completion: c-x c-l
If you have several words you would like to complete, you can use c-x c-p to extend the match.

Move to the declaration of functions / classes
To enable move to the declaration of functions / classes feature you must install exuberant-ctags package and generate tags database.
To generate tags database (and save it in .vimtags file) you can run below script (example for Symfony Framework):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
# Check if is root
if [ ! -f 'symfony' ]
then
echo "Please run script from project root dir"
exit 1
fi

# Get working dir
MYDIR=`dirname "$0"`
if [ ! -d $MYDIR ]; then MYDIR=`dirname "$PWD/$0"`; fi

exec ctags-exuberant -f .vimtags \
-h ".php" -R \
--exclude="\.svn" \
--totals=yes \
--tag-relative=yes \
--PHP-kinds=+cf \
--regex-PHP='/abstract class ([^ ]*)/\1/c/' \
--regex-PHP='/interface ([^ ]*)/\1/c/' \
--regex-PHP='/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/'

After run above script you will get .vimtags file, which is loaded to VIM when it is run in main Symony directory.
You can load external tags file with command: :set tags=/path/to/.vimtags

Move to the declaration: c-]
Return to last edited file / place: c-t
Open declaration as new screen: c-w ]
Open/close list of current file functions: f8

Project files
VIM file list
Open/close file list: f7
Open directory/file: select directory/file and press cr
Open as new tab: select it and press t
Open as new screen: select it and press s or i

Version Controlling System – SVN
Before running any command from VCS you should write a file (:w)
Commit file: \cc
Status: \cs

Other VCS commands:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
\ca VCSAdd
\cn VCSAnnotate
\cN VCSAnnotate!
\cc VCSCommit
\cD VCSDelete
\cd VCSDiff
\cg VCSGotoOriginal
\cG VCSGotoOriginal!
\ci VCSInfo
\cl VCSLog
\cL VCSLock
\cr VCSReview
\cs VCSStatus
\cu VCSUpdate
\cU VCSUnlock
\cv VCSVimDiff

VIMDiff
do – Get changes from other window into the current window.
dp – Put the changes from current window into the other window.
]c – Jump to the next change.
[c – Jump to the previous change.
c-w c-w – Switch to the other split window.

Miscellaneous
Fast close file Shift-ZZ

Appendix

zp8497586rq

Author: Rafał Żelazko

Freelancer. Experienced J2EE, PHP, JS Developer. Advanced Linux user. WebPerfekt.pl owner.

2 thoughts on “Vim IDE and PHP / Symfony / Web develompment”

  1. You have the following in your .vimrc:

    ” ESC-c … capitalize current word (and goto next word)
    map c viwu~W
    ” ESC-l … lowercase current word (and goto next word)
    map l viwuW
    ” ESC-u … uppercase current word (and goto next word)
    map u viwUW

    Which uses the visual selection, thus clobbering it. You won’t regain your previous visual selection if you use the command gv after using one of those mappings. Also, if you have done substitutions with the command :’s it will lose the previous visual area it remembers. You can instead use the following commands:

    “Capitalize first letter of a word, move to next WORD
    guiw~W
    ” Lower case a word, move to next WORD
    guiwW
    ” Upper case a word, move to next WORD
    gUiwW

  2. Blog software clobbered some of the characters in my reply above.Where it says :’s I meant the ex command you get when you have a visual selection and type the characters :s

Comments are closed.