3

I'm reading vim help about the line function and here is an example I found:

:let failed = append(line('$'), "# THE END")

In my vimrc I also found line('.'). The documentation says:

line( {expr}) Number line nr of cursor, last line or mark

I tried to invoke it as

:echo :call line('$')

but this printed the following error:

E121: Undefined variable: :call
E15: Invalid expression: :call line('$')

What does '.' and '$' mean here and how to invoke it correctly?

  • 1
    What doc have you read? If you found :h line() the 3rd and 4th lines describes what . and $ means. – statox Sep 29 '16 at 9:44
  • @statox :h functions. Didn't think there were docs for each function, – user3663882 Sep 29 '16 at 10:25
  • One of the strength of Vim is that everything is documented you might be interested in reading this question – statox Sep 29 '16 at 10:46
  • 1
    The whole idea with calling functions syntax is: if you use the returned value, you don't need to use call; but, if you are just calling the function, then you need to use call. So, :echo line('$') or :call line('$'), but not :echo :call line('$'). – VanLaser Sep 29 '16 at 11:28
8

In :help line all possible values of {expr} are explained:

.       the cursor position                                 
$       the last line in the current buffer                 
'x      position of mark x (if the mark is not set, 0 is returned)                                           
w0      first line visible in current window                
w$      last line visible in current window                 
v       In Visual mode: the start of the Visual area (the   
        cursor is the end).  When not in Visual mode        
        returns the cursor position.  Differs from '< in    
        that it's updated right away.

And to invoke that you just need:

:echo line('.')

call is for running functions:

function! func()
    echo line('.')
endfunction

If you would have something like that in your .vimrc, then you could use call like so: :call func()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.