4

One can use col('$') to get the length of the current cursor line. Further, one can use virtcol('$') to get the same length, but this returns the actual screen column. However, it ignores the conceal feature.

Is there any way to get the column number similar to col() and virtcol() that takes the conceal into account?

2
  • I think the answer to this is "no". At least, I have not figured out any way to do it. Commented Feb 8, 2016 at 7:29
  • 1
    No, and I think this is in the todo list to have this fixed. Also according to Bram, things like '|' should consider concealed items. Commented Mar 3, 2016 at 13:08

1 Answer 1

2

The only way that I can figure out is to make a function which loops over all the characters in the line and checks if it's concealed with synconcealed().

This seems to work well for help files:

fun! VisualCol()
    let l:substract = 0
    for l:i in range(0, col('$'))
        if synconcealed('.', l:i)[0]
            let l:substract += 1
        endif
    endfor

    return virtcol('$') - l:substract
endfun
2
  • This seems to work well for getting the length of the concealed line, but it does not quite work as a substitute for col(). I would add an argument that is passed to col and virtcol. Anyway, thanks! Commented Mar 4, 2016 at 12:46
  • @KarlYngveLervåg Yeah, it could be expanded a bit :-) Feel free to edit! Commented Mar 4, 2016 at 16:38

Your Answer

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

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