Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

column number and Unicode characters #6161

Closed
roxma opened this issue Feb 23, 2017 · 4 comments
Closed

column number and Unicode characters #6161

roxma opened this issue Feb 23, 2017 · 4 comments
Labels
closed:question issues that are closed as usage questions

Comments

@roxma
Copy link
Contributor

roxma commented Feb 23, 2017

你|好

Where | is the cursor position, I got col(.) == 4

I know that the first character "你".encode('utf-8') is b'\xe4\xbd\xa0' , has a length of 3, which is why the next character gets the col(.) as 4

But from the user's perspective, the col(.) should be 2 for h or l motion keys.

Is this intentional? Things get tricky for completion plugin when Unicode character is present.

@fmoralesc
Copy link
Contributor

It is intentional, since col() is supposed to return the byte, not the visible column.

Moving to virtcol() doesn't help, though, I think, because that returns the position of the last column a character occupies. In the example above, it returns 2 when the cursor is above and 4 above , but I think it would be more consistent if it returned 1 and 3.

As far as I can tell, there is no function to get the character position in a line, as opposed to the byte or the visible column it might occupy.

@justinmk
Copy link
Member

see #68 (comment)

As far as I can tell, there is no function to get the character position in a line, as opposed to the byte or the visible column it might occupy.

It was added a few months ago in Vim (and merged to Nvim), see :help strgetchar, :help strchars, :help strwidth, etc.

@fmoralesc
Copy link
Contributor

@justinmk what about the behavior of virtcol()? Do you think it is sensible as is?

@justinmk
Copy link
Member

In the example above, it returns 2 when the cursor is above 你 and 4 above 好, but I think it would be more consistent if it returned 1 and 3.

Seems weird, but as long as it's consistent it doesn't matter, right? It's funny that :set ruler agrees with you. It's too late to change virtcol(), though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:question issues that are closed as usage questions
Projects
None yet
Development

No branches or pull requests

3 participants