Thursday, June 3, 2010

Developing PHP in VIM - VIM IDE for PHP

SkyHi @ Thursday, June 03, 2010

I was going to write something long and smart about how its important to know what YOUR NEEDS are when it comes to coding and using specific IDEs and how do they satisfy them, but decided its best to cut to the chase and just post my VIM configs as requested by several from NYC Drupal User Group during our Feb 10 2010 monthly meetup.


VIM

Attached to this post ZIP file contains customized .vimrc and .vim folder which contains several plugins which make vim very useful when developing in PHP. Contents are dot files so you will not see them unless viewed through terminal or enable displaying hidden files on unix system. P.S. Windows users can use the same .vimrc and .vim but make sure to google for instructions where to place them correctly.


Place both .vimrc and .vim in your $HOME directory so each will have the following respective paths: ~/.vimrc and ~/.vim


CTAGS

Attached _.ctags.txt file is CTAGS customization to perform PHP language map to drupal specific file extensions such as .test, .module, etc... Instructions: Place this file into webroot of your website that you are developing and make sure to rename it to ".ctags" (no leading _ and no .txt, i added these to be able to upload the file). To generate tags file you will need to run the following command in your webroot where you placed .ctags file (without quotes): "ctags -R ."


Without this file ctags will not know how to handle drupal specific files and you will not be able to use IDE features like code completion and jump to resource definition


If it is not clear how to use the customized plugins and other features once installed, leave a comment with your question for me to reply to.


edit:Last notes of wisdom: Make sure you are using _vim_ 7.2 or later, not _vi_(see the missing _m_?). Thx Rob Loach.








AttachmentSizeHitsLast download
myvim.zip400.39 KB11721 hours 37 min ago
_.ctags_.txt50 bytes18321 hours 36 min ago

I suggest installing vim-full. The default vim package tends to be more limited in functionality. Also the ctags package name may be different.

So:
sudo apt-get install vim-full exuberant-ctags

3. Screen and VIM

hey litwol, thanks for the heads up on the vim and ctags configuration. i also started messing with Screen too. luckily you mentioned it during that meetup. As of now i got vim and screen configured but when i run vim in screen i can't get the colors highlighting to come up. it works outside of screen tho.

here is my ~/.screenrc config if anyone wants. im sure it can be better, but its a good starting point:

also when i split the screen, how do u scroll up/down in that specific window? cant seem to figure that out.

got all of this from:
http://bbs.archlinux.org/viewtopic.php?id=55618

------------- ~/.screenrc ----------------------
term xterm-256color
autodetach on
startup_message off
activity "%c activity -> %n%f %t"
caption always "%{= Wk}%-w%{= Bw}%n %t%{-}%+w %-="
vbell off
defscrollback 5000

bind c screen 1
bind 0 select 10

# F8 to turn the status bar off
#bindkey -k k8 hardstatus alwayslastline
# F9 to turn the status bar on
#bindkey -k k9 hardstatus alwaysignore
# F5 and F6 to move one screen forward or backward
#bind F7 to change focus window
bindkey -k k7 focus up
bindkey -k k8 focus down
bindkey -k k5 prev # change window with ctrl-left
bindkey -k k6 next # change window with ctrl-right

#let pgup/pgdn scroll under urxvt (see .Xdefaults)
bindkey "^[[5;2~" eval "copy" "stuff ^u"
bindkey -m "^[[5;2~" stuff ^u
bindkey -m "^[[6;2~" stuff ^d

hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'

# Default screens
screen -t TAB1 1
split
focus down
screen -t TAB2 2
screen -t TAB3 3
select 2

4. Installed!

When I ran "vi", I got a bunch of errors. Forgot this was for "vim" :-) .

So, you'll need:
sudo apt-get install vim ctags






REFERENCES
http://litwol.com/content/developing-php-vim-vim-ide-php