I am trying to use
wordcount().cursor_chars to determine the character offset of the cursor in the buffer – but I am getting off-by-one errors.
The docs for
wordcount() say that
cursor_chars is the "Number of chars before cursor position (not in Visual mode)".
However if you:
- open a new buffer
:autocmd CursorMoved,CursorMovedI * echo wordcount()
- return to normal mode and place the cursor on the
1. However I would expect this to be
0 as there are no characters before the cursor. Is the documentation wrong?
A to go into insert mode with the cursor after the
c gives a cursor offset of
4 in a file with unix EOLs and
5 in a file with dos EOLs. Is that because the cursor is actually on the last character of the EOL regardless of whether the EOL is one or two characters?