unicodevim

vim: why col() returns a byte's position, not column


While editing Unicode text, I realized that Vim function col('.') returns current byte position on the line, not character nor column. So this code doesn't work properly:

let cur_column = col('.')
...
execute "normal! " . cur_column . '|'

It moves the cursor on a wrong forward position every time I'm on a non-ASCII line.

I'm using airline plugin, which shows me a cursor position in statusline, and it uses byte position too. But on vim without any plugins it shows me line, byte-character, so presumably it's possible to get a right position.


Solution

  • You can use another function:

    virtcol('.')
    

    which is the screen column of cursor.