1

I am using a vimscript to "highlight" columns of interest in some text. However, using colorcolumn "highlights" the entire column on every row in the file. Is there a good way to define start and end rows for the colorcolumn to be applied on?

More information: 1. I know the row numbers I would like to highlight , so the solution should be based on row numbers. 2. I expect this to be a buffer and/or window setting , not a global setting.

Thanks

  • 1
    Welcome to this site! With the built-in colorcolumn it is not possible do to what you want: you will need to find a custom solution. How do you want to define the start and end rows for your highlighting? With line numbers, with a pattern, with a text object, should it be local to window like colorcolumn, or should it be a global setting, or a buffer local setting? Your question might need some extra details so that others can answer you :) – statox Nov 5 '19 at 14:00
  • Hi Thanks for your answer. using line numbers is good (as my script already "knows" the lines I want to highlight) and buffer local setting is good as well, or window , what ever is easier to achieve. – Avi Nov 5 '19 at 14:04
  • 3
    That is not possible. You might be able to do something using \%c or \%v regex atoms. – Christian Brabandt Nov 5 '19 at 14:33
1

I can't help but feel that you are trying to limit the colorcolumn to the 81st (or so) column only when there actually is a line that goes beyond that column. I'm sorry, if I got your question wrong, because I'm a bit confused about rows vs columns...

Anyway: this is what I have in my .vimrc:

" Make 81st column stand out
highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)

This is not my idea, it's taken from Damian Conway's video "more instantly better vim"

Again: Sorry, if I misunderstood your question.

| improve this answer | |
  • Hi Thnks for your answer. This is not what I am looking for , I have a text report with many fields separated by spaces. I have some script based on “match” to find the column numbers I want to highlight (might differ between reports). However, using colorcolumn highlights entire column across all window, including lines outside the numerical section of the report. My goal is to highlight the columns only in part of the report. – Avi Nov 5 '19 at 16:19
  • 2
    @Avi you need to add the line numbers to your pattern using \%5l for the 5th line. I do something similar for my NrrwRgn plugin here – Christian Brabandt Nov 5 '19 at 17:22
  • 1
    Welcome to Vi and Vim Paul! We appreciate you trying to discern what the OP is asking for and providing an answer, though it doesn't accomplish the exact goals. Good start though – D. Ben Knoble Nov 6 '19 at 14:53
0

Thanks to all the helpers.

I was able to achieve more or less what I was looking for using matchaddpos. The only issue with this is that it is limited to 8 lines at a time , so I had to do the highlight in sections of 8 lines at a time. If anyone has a nice idea how I can use matchaddpos on more than 8 lines at a time would be much appreciated. Avi

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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