[BUG] getpos("'>") returns wrong column number

27 views
Skip to first unread message

ZyX

unread,
Mar 8, 2011, 9:53:04 AM3/8/11
to vim...@googlegroups.com
Consider the following script:

vim -u NONE -s <(echo $'gg0VG:call writefile(getpos("\'>"), "getpos")\n:qa!')

It will end up having [0, 1, 2147483647, 0] as lines in `getpos' file,
while expected to have [0, 1, 1, 0]. Tested on vim-7.3.102 (from Gentoo repos)
and vim-7.3.138 (mercurial rev ea399ac2c1b9). Note that 2147483647 is (2**31-1).
I am on amd64.

signature.asc

James Vega

unread,
Mar 8, 2011, 10:42:14 AM3/8/11
to vim...@googlegroups.com
On Tue, Mar 8, 2011 at 9:53 AM, ZyX <zyx...@gmail.com> wrote:
> Consider the following script:
>
>    vim -u NONE -s <(echo $'gg0VG:call writefile(getpos("\'>"), "getpos")\n:qa!')
>
> It will end up having [0, 1, 2147483647, 0] as lines in `getpos' file,
> while expected to have [0, 1, 1, 0].

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().

--
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <jame...@jamessan.com>

Reply all
Reply to author
Forward
0 new messages