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?

  • I think the answer to this is "no". At least, I have not figured out any way to do it. – Karl Yngve Lervåg Feb 8 '16 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. – Christian Brabandt Mar 3 '16 at 13:08
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
  • 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! – Karl Yngve Lervåg Mar 4 '16 at 12:46
  • @KarlYngveLervåg Yeah, it could be expanded a bit :-) Feel free to edit! – Martin Tournoij Mar 4 '16 at 16:38

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.