Vim highlighting sometimes requires a kickstart?

99 Views Asked by At

Centos 6, vim 7.2.411, my .vimrc file:

autocmd BufNewFile,BufRead *.html set filetype=php
set tabstop=4
set shiftwidth=4
set nowrap
set autoindent
set number
if has('mouse')
  set mouse=a
endif
set backspace=start,indent,eol
set t_Co=256
colorscheme molokai

(Although I code in php I save my files as .html - a bad practice I imagine? But something I started in this project years ago when I thought I was being clever - security through obscurity etc, and I don't have the time/inclination to change it now)

Generally the colorscheming works, but sometimes I'll load a file and it'll be out of whack, like there's an unclosed string somewhere or similar. Scrolling up and back down tends to fix it, though sometimes I need to go into insert mode and add a newline for it to "wake up".

How can I fix this?

1

There are 1 best solutions below

1
On BEST ANSWER

The PHP syntax plugin allows to configure this; cp. :help ft-php-syntax:

Selecting syncing method:

let php_sync_method = x

x = -1 to sync by search (default), x > 0 to sync at least x lines backwards, x = 0 to sync from start.

The different sync options are documented under :help :syn-sync. You have to understand that this always is a trade-off between correctness (:let php_sync_method = 0) and performance. Experiment with different values, and decide for yourself with what amount of delay / manual refreshes you can live with.