Pages

Showing posts with label Vim. Show all posts
Showing posts with label Vim. Show all posts

Friday, April 17, 2009

Checking PHP Syntax from VIM

I use vim/gvim for my text editor and I found a handy way to quickly check PHP syntax using a couple of keystrokes from within the editor. Add this to your vimrc file:

" Check php syntax on the current file with CTRL+L
autocmd FileType php noremap <C-L> :!/usr/bin/php -l %<CR>

As an added bonus, you can also use a key mapping to run the execute the PHP file as well, though I find this less useful on a daily basis.

" Run php cli on the current file with CTRL+M
autocmd FileType php noremap <C-M> :w!<CR>:!/usr/bin/php %<CR>

You can change the key used to trigger the command, but you have to be careful not to interfere with pre-existing key combinations.

Thursday, February 26, 2009

Vim and Spell Check

I often need to check my spelling when marking up websites or coding for website output. Thankfully, my text editor of choice has a nifty spell check feature. The key is

:set spell

You can add this to your vimrc or just type it in command mode. And I guess if you wanted to be really fancy, you could enable spell-check per file type, but I went the vimrc route. Also, when using gvim, you can enable or disable spell check from the Tools > Spelling Menu. This menu also gives some hints for using the spell checker.

After enabling spell check, you'll notice blue and red underlines under certain words; blue is apparently for grammar syntax (such as failing to capitalize a word) and red is for spelling errors.

  • ]s and [s goes to next or previous error respectively.
  • When the cursor is over a word, use z= for suggestions.
  • :spellrepall repeats a correction.

As usual, there are lots more features to explore. Check out vim help or go to the vimdoc site:

http://vimdoc.sourceforge.net/htmldoc/spell.html