Highlight specific column in VIM
Asked Answered
F

2

12

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?

Fall answered 18/7, 2011 at 9:9 Comment(0)
P
24

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

Philology answered 18/7, 2011 at 9:20 Comment(6)
A variant to reduce monotonic typing: :let &l:cc = join(range(31,39),','). By the way, :setlocal could be a bit more appropriate in your case too.Exocentric
Thanks a lot. I didn't know yet that colorcolumn supports more than one column.Fall
Now... I wonder if it's possible to base this on the current visual selection... that would be great... :) I'm diving in... :)Fall
@exhuma: Sounds interesting. You could post another SO question for it (and answer it yourself when you figure it out). I know I'd upvote it :)Philology
@merlyn: got it working just now. Actually it's quite simple. I'll work out the details and try to map it on a key. Once done, I'll post it.Fall
Here's the answer: #6759232Fall
G
3

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=

Glossa answered 26/2, 2018 at 17:44 Comment(1)
This might be of interest as well for something similar: github.com/Yggdroot/indentLineFall

© 2022 - 2024 — McMap. All rights reserved.