Archive for the ‘vim’ Category

Integrating JavaScript lint with vim

Sunday, March 18th, 2007

After looking for a lint program for JavaScript, I’ve found JavaScript Lint and after a few pokes around the documentation and forum, got it installed and integrated with vim.
I posted this information to the Irish PHP Users’ Group mailing list on Wednesday – thought I’d share it to a wider audience tonight.

This is how I did it, note this process now only works with the downloaded package JavaScript Lint 0.3.0:

I got, compiled and installed javascriptlint:
$ svn co https://svn.sourceforge.net/svnroot/javascriptlint/trunk javascriptlint
$ cd javascriptlint
$ make -f Makefile.ref all
$ cd Linux_All_DBG.OBJ/
$ sudo cp jsl jscpucfg /usr/local/bin/
$ #generate default config file (and edit to taste)
$ jsl -help:conf > /etc/jsl.conf

I added the following lines to the “Defining identifiers” section of jsl.conf, as JavaScript Lint
doesn’t know anything about DOM objects in web browsers.

+define window
+define document
+define alert
+define XMLHttpRequest
+define ActiveXObject
+define Image
+define parent
+define dispatchEvent
+define screen
+define navigator
+define setTimeout

I also turned on the ‘option explicit’ settingÅŸ which causes the linter to catch undeclared variables in the “Defining identifiers” section.

For integrating with vim I added these lines to my ftplugin/javascript.vim file:

set makeprg=jsl\ -nologo\ -nofilelisting\ -nosummary\ -nocontext\ -conf\ '/etc/jsl.conf'\ -process\ %
set errorformat=%f(%l):\ %m
"make F10 call make for linting etc.
inoremap <silent> <F10> <C-O>:make<CR>
map <silent> <F10> :make<CR>

fold error in javascript.vim

Saturday, March 17th, 2007

I discovered Yi Zhao’s replacement for javascript.vim which has better syntax highlighting for .js files. One slight problem though – straight after I copied it into my ~/.vim/syntax directory all my fold settings stopped working.
To fix this edit javascript.vim and change “setlocal foldlevel=6″ to “setlocal foldlevel=0″.

ViM for PHP Programmers

Monday, February 19th, 2007

I got to read the presentation notes that Andrei Zmievski from Yahoo put on the web after giving his talk on ViM for PHP Programmers at the PHP Vancouver Conference.

I’ve been using vim for ages (at least since ’99 when I wrote Intro to vim for the Irish Linux Users’ Group linux.ie website) and I have to say Andrei pointed out functions that I wasn’t aware of.

It’s also nice to see that Tobias Schlitt’s “phpDocumentor for Vim” plugin got a mention in Andrei’s notes as it is extremely useful for generating phpdoc comments in vim.

Great stuff!

using F5 to toggle spellcheck in vim 7

Wednesday, November 29th, 2006

After having this working for a while, I thought I’d share this section from my .vimrc:

inoremap <silent> <F5> <c -O>:call SpellToggle()<cr>
map <silent> <F5> :call SpellToggle()<cr>
function SpellToggle()
    if &spell == 1
        set nospell
    else
        set spell
    endif
endfunction

Frappr’s map of Vim users

Friday, December 16th, 2005

Just a quick note to say I’ve joined Frappr’s map of Vim users – have you?

As an aside, Frappr seems to be quite similar to Orkut, in that it is a community site for staying in touch with [and making new] friends. I can only hope that it is less prone to crash, which is one thing that really irritates me about Orkut.

phpDocumentor for Vim

Thursday, October 13th, 2005

Tobias Schlitt wrote an excellent “phpDocumentor for Vim” plugin that I’ve started using in work. It works very well at generating phpDocumentor tags with intelligent defaults, some based on the code in your vim window.

quicker way to code in vim

Monday, August 15th, 2005

I’ve been experimenting with Thomas Link’s excellent tSkeleton plugin for the vim editor recently.

tSkeleton provides file templates and code skeletons which are parsed and expanded when you edit your code. It currently comes with templates for PHP, Ruby, vim scripting and many other languages too.

There are some parts of tSkeleton which will only work when using the gtk-gui version of vim (or the Windows version); the popup menus for example but I’m not going to let that stop me.

This is a brief outline of how I got it working after a few false starts:

  1. Download the multvals and genutils scripts that tSkeleton requires from vim.org and uncompress them until some useful directory. I put them into my /home/kguest/config/vim/scripts/ directory.
  2. Add entries to your ~/.vimrc to source these files:
    source /home/kguest/config/vim/scripts/multvals.vim
    source /home/kguest/config/vim/scripts/genutils.vim
  3. Download the tSkeleton.zip file and uncompress it’s contents into your ~/.vim directory.
  4. Add lines similar to these into your ~/.vimrc
    autocmd BufNewFile ~/.vim/skeletons/*.suffix TSkeletonSetup othertemplate.suffix
    autocmd BufNewFile *.suffix TSkeletonSetup template.suffix
  5. Next you’ll need to copy a directory or two from ~/.vim/skeletons/bits.samples/ to ~/.vim/skeletons/bits/ - I only copied the php directory over.
  6. Finally you may want to set some some details in your .vimrc so tSkeleton can expand the templates with slightly more meaningful information. I added these lines:
    let tskelUserName='Ken Guest'
    let tskelUserEmail='ken@guest.cx'