5

I am working with an HTML file and within a <script> tag specifically. I usually fold my code using the marker method. However an annoying behavior sometimes happens with my syntax highlighting when I fold code. Example:

<script type="text/javascript">
    // init {{{1
    window.onload = init;                                            
    function init()                                                  
    {                                                                
        window.addEventListener('message', messageHandler, false);   
        GDT_MSG.requestSliceInfo();                                  
        GDT_MSG.requestSelected();                                   
        GDT_MSG.requestNetworkGraph();                               
    }                                                                
+-- 11 lines: Parser: GLOBAL VARIABLES ------------------------------

+-- 60 lines: Message Handler ---------------------------------------

    // Live Monitoring: Global Variables {{{1                        
    /* arrays and important settings for live monitoring*/           
    var pkts = [];                                                   
    var bytes= [];                                                   
    var dataset;                                                     
    var accum_data;                                                  
    var totalPoints = 900;                                           
    var displayPoints = 60; // Initially displays the last minute    
    var plot;                                                        
    var updateInterval = 5000;                                

The code that is above "GLOBAL VARIABLES" is correctly highlighted whereas the code below "Message handler" is not.

This annoyance fades away when I unfold all my folds... but of course this is not what I want. Does anyone know how to fix this?

0

1 Answer 1

5

You can read more about why this happens by looking at :help :syn-sync. The short answer is that vim decides to redraw the screen and starts from some point in the middle of the file. It incorrectly guesses the syntax at this starting point and it messes up the rest of the file.

To fix this, I generally use this mapping, which I got from Steve Losh's dotfiles:

nnoremap U :syntax sync fromstart<cr>:redraw!<cr>
2
  • 1
    Works like a charm! Thanks! BTW, U as "Unfuck my screen" is hilarious lol
    – Sergio
    Commented Feb 24, 2015 at 17:21
  • Haha yeah, I'm glad you clicked through to read that. His configs have a number of helpful and funny things in them
    – Matt Boehm
    Commented Feb 24, 2015 at 18:20

Your Answer

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

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