Thursday, December 12, 2013

getline(-1) returns 0

Can someone explain the following behavior?

The command

:echo getline(-1)

returns zero instead of an empty string. The corresponding help page states the
following.

> When {lnum} is a String that doesn't start with a digit, line() is called to
> translate the String into a Number.

> When {lnum} is smaller than 1 or bigger than the number of lines in the
> buffer, an empty string is returned.

Perhaps negative numbers are treated as strings and translated to zero by
line():

:echo line("-1")

returns zero. Using zero as an argument for getline(), the result should be an
empty string, as

:echo getline(0)

returns an empty string.

Thanks in advance.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment