Describe the bug
getcurpos()[4] (curswant) returns 2147483647 after $ motion
To Reproduce
Detailed steps to reproduce the behavior:
vim --clean (or gvim --clean, etc.):au CursorMoved * echo getcurpos()[4]
then motion $ on a line with text.
2147483647, and that is shown in the command line.j or k after that still shows that value.Expected behavior
a value == virtcol("$") I guess?
Environment (please complete the following information):
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/vim/vim/issues/4464%40github.com.
For more options, visit https://groups.google.com/d/optout.
Closed #4464.
I understand that there is a technical reason behind this value:
That's intentional. Vim defines a MAXCOL value which is used to
indicate the cursor is at the end of the line without specifically
requiring knowing the line length ahead of time. This allows the
behavior to stay the same even if the line length changes. Some of its
uses are purely internal, but it does have external visibility in the
case of commands like getpos().
Source: https://groups.google.com/g/vim_dev/c/oCUQzO3y8XE/m/opuczWwCtCsJ
But I still think that it looks unexpected for a plugin author. I wonder whether it would make sense to at least change the output of getpos():
vim9script setline(1, 'some text') exe "norm! V\e" echom getpos("'>")
[0, 1, 2147483647, 0]
Otherwise, we have to fix it like this:
vim9script setline(1, 'some text') exe "norm! V\e" var pos: list<number> = getpos("'>") pos[2] = col([pos[1], '$']) echom pos
[0, 1, 10, 0]
As an example, this is what the vim-exchange plugin has to do here.
If it can't be changed because it would break the compatibility with existing legacy Vim scripts, maybe we could limit this change to Vim9 scripts?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
I think it's working as intended, the problem is maybe that the behaviour is undocumented.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Interestingly enough, getpos() is affected but not getcharpos():
vim9script setline(1, 'some text') exe "norm! V\e" echom getpos("'>")
[0, 1, 2147483647, 0]
vim9script setline(1, 'some text') exe "norm! V\e"
echom getcharpos("'>")
[0, 1, 9, 0]
Which seems inconsistent.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
I understand that there is a technical reason behind this value:
That's intentional. Vim defines a MAXCOL value which is used to
indicate the cursor is at the end of the line without specifically
requiring knowing the line length ahead of time. This allows the
behavior to stay the same even if the line length changes. Some of its
uses are purely internal, but it does have external visibility in the
case of commands like getpos().Source: https://groups.google.com/g/vim_dev/c/oCUQzO3y8XE/m/opuczWwCtCsJ
But I still think that it looks unexpected for a plugin author. I wonder whether it would make sense to at least change the output of
getpos():
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
I think it's fine that getcharpos() returns the character index of the last character in the line. Returning a large number isn't helping. In case the script needs to know the position is actually "beyond end of the line" then getpos() can be used. Thus it's actually useful to have the two function return something different.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()