I really want to know why doesn't Vim's v:lnum
return 1 for very first line. I tried googling and searching in Vim's docs, but I can't find an answer.
I understand that v:lnum
returns line number, but I don't understand which line v:lnum
is referring to..? A little aside; from help v:lnum
I understand that you can only use v:lnum
with some expressions including indentexpr
(the one I'm interested in the most for my indentation script).
workflow test 1
- make a
.vim
file. e.gcheck.vim
- append
echo v:lnum
- open new vim window and
:source check.vim
- append some text to the file and
:source check.vim
again - no matter how many lines I add to the file I always get
0
back
I think I understand this, since Vim docs say that v:lnum
only works in conjunction with some specific expressions then you would expect 0
when I'm trying to use v:lnum
by itself.
workflow test 2
- make
check.vim
file append
setlocal indentexpr=Check() function! Check() let line = getline(v:lnum) echo v:lnum line endfunction
open new vim window and
:source check.vim
- append some text to the file and
:call Check()
function - I DON'T get first line no matter what I do.. I can get any other lines.. e.g
- if I only type in one line into the file and
:call Check()
I get0
and''
- if I type in second line into the file and
:call Check()
I get2
andcheck line two
back - if I keep adding lines to the file and run
:call Check()
on lets say the fifths line I get5
andcheck line five
- if I only type in one line into the file and
I think I understand that v:lnum
returns index of the last line typed into the file. But why doesn't it return the index of the very first line type?