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. 🙂

Entry filed under: Linux, PHP.

Enable MySQLi Extension in PHP Bugzilla 2.18.3 Stopped Working

5 Comments Add your own

  • 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

    Reply
  • 2. bawigga  |  October 24, 2008 at 4:43 pm

    Awesome, Thanks!

    Reply
  • 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

    Reply
  • 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

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


July 2007
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Recent Posts

Top Clicks

  • None

Feeds


%d bloggers like this: