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

3
  • 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, 2019 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, 2019 at 14:04
  • 3
    That is not possible. You might be able to do something using \%c or \%v regex atoms. Nov 5, 2019 at 14:33

2 Answers 2

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.

3
  • 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, 2019 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 Nov 5, 2019 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, 2019 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

1
  • Suppose you add some detail to this so others can copy you? - at least a link to matchaddpos. If your answer then constitutes an actual answer you could select it as the accepted answer as well.
    – NeilG
    Jun 21 at 2:14

Your Answer

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

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