Search code examples
vimhighlighting

Highlight specific column in VIM


I work a lot with files which contain data on fixed positions. Non-delimited "CSV" files if you will... Often, I'd like to highlight a specific column.

I tried

:match ErrorMsg /\%>30v.\+\%<40v/

but this runs extremely slow and only matches the first line. I suppose the file may be too large for this. Mind you, the files are very wide (around 40000 characters) but not very long (around 2000 lines). The data originates from old tools over which I have no control.

Example file:

                                                 63082                                                   
                                                 01089                                                   
                                                 75518                              735301               

                                                 53473                              017146               
                                                                                     37217               
                                                                                        07               
                                                                                    940376               
                                                   762                                2842               

                                                                                     88331               
                                                 40680                                8928               
            645718                                                                                       
                                                  0131                                                   
                                                                                     03522               

             47210                                                                   27431               

             93837                                                                                       
                                                                                   8825072    49479415   

                                                 52084                                8940               
                                               0591705                              205635               
                                                                                    525429               
                                                 65339                                 300               


                                                  0397                                                   
                                                                                      1983               
                                                     0                                                   
                                                                                   2605768               
            121991                                                                     648               
                                                  3892                                                   

                                                  1260                                                   

Any ideas?


Solution

  • Are you using Vim 7.3?

    Apparently they just recently added a colorcolumn option.

    Try:

    :set colorcolumn=31,32,33,34,35,36,37,38,39
    

    Note that :help 'colorcolumn' says "Will make screen redrawing slower". I somewhat replicated your scenario, though, by using pure blocks of 1234567890 with the exact repetition count you specified.

    The command you mentioned is very slow. colorcolumn isn't.

    but this runs extremely slow and only matches the first line

    By "first line" do you mean the first displayed line, when word wrapping is enabled? Unfortunately colorcolumn will exhibit the same behavior...