Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 433
exhuma Avatar asked Jul 18 '11 09:07

exhuma


2 Answers

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...

like image 75
Merlyn Morgan-Graham Avatar answered Oct 19 '22 19:10

Merlyn Morgan-Graham


This is off the original topic, but Google leads people here. When trying to fix a horribly indented YAML or any other swiftwidth=2 file, I really struggle to visually recognize what is and isn't in a valid column. A comment by @ib to the accepted answer lead me to this gem.

:let &l:colorcolumn = join(range(3,15,2),',')

It basically says set colorcolumn to the comma delimited string value of 3 through 15 counted by 2. (In other words: :set colorcolumn=3,5,7,9,11,13,15) The result looks like this:

enter image description here

You can do a simple :set colorcolumn to see what value results.

To get rid of it do :set colorcolumn=

like image 31
Bruno Bronosky Avatar answered Oct 19 '22 18:10

Bruno Bronosky