VIM Syntax Highlighting
July 11, 2007 at 6:26 am 5 comments
For anyone who uses CakePHP 1.2 branch should know the template/view files now end with the .ctp extension (instead of .thtml). However, Vim doesn’t recognize that extension so syntax highlighting won’t be activated when you edit the files in Vim. Last thing I want to do is to code in Vim without syntax highlighting! To remedy the problem, I simply modified the filetype file to tell Vim to syntax highlight .ctp files as .php files. To do so in Ubuntu 7.04, open the filetype:
vi /usr/share/vim/vimcurrent/filetype.vim
Search for the string “php” and you will find the lines you need to modify and just add *.ctp like below:
" Php, php3, php4, etc. au BufNewFile,BufRead *.ctp,*.php,*.phpd setf php
Next time you open any .ctp file you will be greeted with those beautiful colors again that inspire us to write more wonderful code in PHP. 🙂
1.
AD7six | July 13, 2007 at 9:10 am
Thanks, I’ve been wondering about that.
Might want to add sudo to your suggested vi command, since afaik that file isn’t writable otherwise. Maybe that’s a bit obvious, but then again 🙂
Cheers,
AD
2.
bawigga | October 24, 2008 at 4:43 pm
Awesome, Thanks!
3.
Sebastian | February 3, 2009 at 12:34 pm
Wrong approach, because you are changing the core files. Instead, add the following lines to your .vimrc file:
if has(“autocmd”)
autocmd BufEnter *.ctp set syn=php
endif
Cheers,
Sebastian
4. acloudtree » Blog Archive » Ubuntu + VIM + CakePHP 1.2 + .ctp syntax highlighting | February 22, 2009 at 6:20 am
[…] blog […]
5.
Ian M. Jones | April 7, 2011 at 10:55 am
I agree with @Sebastian, this should be something set in your .vimrc file, not in the core files.
But I struggled with Sebastians method, gave me errors. But putting the following into my .vimrc worked fine:
au BufNewFile,BufRead *.ctp set filetype=php
Cheers,
Ian