Consider the following snippet:

var winid = win_getid()
var winwidth = winwidth(winid)
var range = []
for lnum in range(10, 20)
    add(range, [lnum, 0, winwidth(winid)])
var m = matchaddpos("CursorWord0", range)

According to :h matchaddpos() the second argument can be

- A list with two numbers, e.g., [23, 11]. The first number is
  the line number, the second one is the column number (first
  column is 1, the value must correspond to the byte index as
  |col()| would return).  The character at this position will
  be highlighted.
- A list with three numbers, e.g., [23, 11, 3]. As above, but
  the third number gives the length of the highlight in bytes.

In-spite I use winwidth(winid) as third element of each three-dimensional list, I get highlighted only the text. What I mean is that, for example, if I have a line that contains 3 characters:


and my window width is 150, then I get highlighted only the first 3 columns whereas I want to highlight ALL the 150 columns.

On the same topic: how to define a pattern that ends where the window end?

For example, if I want to highlight a line from "\^XXX" to the end of the current windows, I am thinking to define a pattern as "\^XXX* but I have no idea on how to end it to specify the end of the current window.

  • You can only highlight cells with characters in them.
    – romainl
    Mar 31 at 9:10
  • Ok, so one way could be to define an event that once a line starts with "XXX" then calls a function that add n empty-spaces until the right edge of the current window? Would that be possible to take another route and exploit the colocolumn (or some similar) option in some way?
    – Barzi2001
    Mar 31 at 9:45
  • What exactly are you trying to achieve? Are you possible looking for the 'wincolor' option? Mar 31 at 14:32
  • @ChristianBrabandt I think I found a solution: in reality I figured that I want to change the background of few specific lines and not the highlight. The best would be to use the analogous of colorcolumn option but which acts by lines (e.g. set colorlines=20) but unfortunately it does not exist. However, I have discovered :h sign that I can use in a for loop to set the background of few specified lines. There is one that I am worried: this command will be triggered upon the event CursorMoved and running a complete for loop every time the cursor moves but that may slow down Vim a lot. Correct?
    – Barzi2001
    Apr 2 at 7:49
  • Yes correct, the only possible solution I know for this is to (ab-)use signs. But this may slow down things a bit. Depends how many signs you need to set and how often you want them to be updated (which has to be done manually. It might also be possible using text-properties. But I have never checked if this is possible there. Apr 2 at 9:10


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.

Browse other questions tagged or ask your own question.