8
# vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 31 2015 23:36:07)
# cat /root/.vimrc 
map <F2> :w\|!sh % <cr>
map <F3> :w\|!bash % <cr>
map <F4> :w\|!python % <cr>
map <F5> :w\|!python % &<cr>

highlight RedundantWhitespace ctermbg=DarkBlue guibg=red
match RedundantWhitespace /\s\+$\|\t/

syntax on
highlight Comment ctermfg=green

I'm starting edit highcharts example htm:

# vi /var/www/js/highcharts/examples/dynamic-master-detail/index.htm

animation of problem

I'm navigating through code and I'm using only the arrow keys and the Home, Page Up, Page Down, and End keys.

After 2 minutes this visual glitch occurs; half of the screen under my cursor loses its syntax highlighting and becomes one color. If I hit Page Down or Page Up, syntax highlighting is restored.

Any html code with javascript inside is affected.

7
  • Does this happen with other terminals you've tried, or only one? Jan 19, 2016 at 22:27
  • In the movie, it is bare xterm. This also is happening in screen inside xterm. What else? konsole? Nope, I didn't tried this, yet. Jan 20, 2016 at 17:57
  • Does it happen also in konsole, then? You should test Jan 20, 2016 at 23:35
  • Yes. It does... Jan 21, 2016 at 5:49
  • Does increasing the minlines setting for your current syntax highlighting help? I.e, :syn sync minlines=800 (adjust as needed).
    – Zilk
    Feb 20, 2016 at 23:12

2 Answers 2

1

This could be an issue with vim's system for recognising and then highlighting syntactic "keywords" not getting enough context to recognise keywords.

The basic concepts of vim's syntax system (finding and tagging basic syntax elements) is explained in :h usr_44

Basically vim uses regex to recognise syntactic elements in a file, once these are identified, then highlighting rules are applied to colorise those code constructs, (i.e. to do "syntax highlighting"), but as explained in :h 44.10 vim doesn't start parsing from the beginning of the file, it starts some number of lines (e.g. 10 or 100 lines) upward from the top of your current viewport.
If a syntactic construct, e.g. an opening HTML tag or a function definition etc starts higher than the point vim starts parsing, vims syntax regex breaks.

Usually to fix this you increase the point that vim starts parsing.
To find out how many lines above the top line of the viewport vim is starting its parsing use:

:syntax sync

Here is my output when viewing an HTML file:

:syntax sync
--- Syntax sync items ---
syncing on items; minimal 10, maximal 100 lines before top line
[lots of other output here...]

if I had a problem with syncing - just for that file - I would increase minlines with

:syntax sync minlines=200

If you repeatedly get this problem fixing it is a bit harder. This is because the sync value is often set in a syntax file dedicated to the filetype you are editing, e.g. for me syntax sync minlines for html filetypes is set in the syntax file

/usr/share/vim/vim74/syntax/html.vim

syntax parsing and config values for css files is in

/usr/share/vim/vim74/syntax/css.vim 

shell is in sh.vim and so on.
These syntax scripts only run at the time you open a file of the type foo.css, bar.html, baz.sh etc, so setting a line in your vimrc won't work because these scripts would blow your settings away, one solution is to use an autocmd which triggers when you enter the file

autocmd BufEnter *.html :syntax sync minlines=200
0

I get these with CMakeList.txt files. It is part of the syntax highlight mechanism. I also get it in "long" (a few pages really) HTML where I have JavaScript code. For these, I use the following command:

:syn sync fromstart

And in most cases it resolves the issue.

Note that the command will make vim very slow if you edit a really large file. In most cases, for me the "slowness" is more than bearable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.