Opening PHP files in vim gives me error: E108: No such variable: "b:current_syntax"

2

I'm running cygwin on my Windows box, and everytime I open up a php file using vim, i get this error:

sendgrid-test.php" 7L, 46C
Error detected while processing /usr/share/vim/syntax/php.vim:
line  112:
E108: No such variable: "b:current_syntax"
Press ENTER or type command to continue

The file opens just fine, but the highlighting is very messed up, it's difficult to get in there and code. I'm not sure where to start so that I can ensure vim has proper syntaxing for PHP on this machine. Does anybody have any ideas?

Thanks, Arie

ariestav

Posted 2012-10-12T16:00:27.957

Reputation: 181

Did you try just deleting the line 112 from the file mentioned? It might just work. – Rudolf Mühlbauer – 2012-10-12T18:04:02.380

The file syntax/php.vim sources other syntax files and apparently expects b:current_syntax to have been set by one of them, syntax/sql.vim, I think. I don't see that error so I wonder if some files are missing from your installation. Try executing ":scriptnames". Towards the bottom of that list you should see /usr/share/vim/syntax/php.vim followed by .../html.vim, .../javascript.vim, .../vb.vim, .../css.vim, .../sql.vim and .../sqloracle.vim. At least that's what I see. – garyjohn – 2012-10-12T18:20:13.933

Here is the result of running :scriptnames: : /usr/share/vim/vimrc
2: /usr/share/vim/syntax/syntax.vim 3: /usr/share/vim/syntax/synload.vim 4: /usr/share/vim/syntax/syncolor.vim 5: /usr/share/vim/filetype.vim 6: /usr/share/vim/plugin/matchparen.vim 7: /usr/share/vim/syntax/php.vim 8: /usr/share/vim/syntax/html.vim 9: /usr/share/vim/syntax/javascript.vim 10: /usr/share/vim/syntax/vb.vim 11: /usr/share/vim/syntax/css.vim 12: /usr/share/vim/syntax/sql.vim
– ariestav – 2012-10-12T18:22:23.073

Which version of Vim? (:version within Vim, or vim --version on the command line) – Heptite – 2012-10-12T18:45:38.773

VIM - Vi IMproved 7.1 (2007 May 12, compiled May 14 2007 16:29:51) – ariestav – 2012-10-12T19:04:03.043

1Very much outdated. If you're using cygwin, you should be able to re-run the cygwin installer and it will update Vim (and probably a lot of other stuff). – Heptite – 2012-10-12T19:12:37.697

Well, cygwin was installed with MobaSSH which included vim. I tried installed cygwin with the installer, but alas it didn't change anything. – ariestav – 2012-10-12T19:31:37.907

As Heptite pointed out, that's a pretty old version of Vim and it's hard to say what bugs may have existed then and have since been fixed. My Cygwin installation is pretty up to date and it's using Vim 7.3.646 compiled Aug 31 2012. If I start it as vim -N -u NONE, execute :filetype plugin indent on, :syntax on and :e foo.php, I don't get any errors. You could debug your current installation using -V with a file or using the :debug command, but that's pretty tedious, especially if you don't know what you're looking for or what to expect. – garyjohn – 2012-10-12T23:13:20.530

Answers

0

You seem to be missing the syntax/sql.vim script, which syntax/php.vim is including. As others have pointed out in the comments, you Vim installation is pretty outdated, so an update might fix things already.

To just pragmatically get rid of the error, create a ~/.vim/syntax/sql.vim file with just

:let b:current_syntax = 'sql'

in it, or change the :unlet at line 112 to :unlet!.

Ingo Karkat

Posted 2012-10-12T16:00:27.957

Reputation: 19 513