Lightline.vim: Showing Full Length of file

Created on 9 Jan 2015  路  4Comments  路  Source: itchyny/lightline.vim

Is there a way for me to show the current line as well as the total number of lines in the current buffer? I would love for it to say 023/106 if I was on line 23 and the file was 106 lines long.

Thanks!

configuration

Most helpful comment

Please read the README.md or the help document. All the following examples should work for you. Choose the one you like.

let g:lightline = {
      \ 'component': {
      \   'lineinfo': "%{line('.') . '/' . line('$')}",
      \ },
      \ }
let g:lightline = {
      \ 'component': {
      \   'lineinfo': "%{printf('%03d/%03d', line('.'),  line('$'))}",
      \ },
      \ }
let g:lightline = {
      \ 'component_function': {
      \   'lineinfo': "MyLineinfo",
      \ },
      \ }
function! MyLineinfo() abort
  return line('.') . '/' . line('$')
endfunction
let g:lightline = {
      \ 'component_function': {
      \   'lineinfo': "MyLineinfo",
      \ },
      \ }
function! MyLineinfo()
  return printf('%03d/%03d', line('.'),  line('$'))
endfunction
let g:lightline = {
      \ 'active': {
      \   'right': [ [ 'syntastic', 'mylineinfo' ], [ 'filetype' ] ],
      \ },
      \ 'component_function': {
      \   'mylineinfo': "MyLineinfo",
      \ },
      \ }
function! MyLineinfo()
  return line('.') . '/' . line('$')
endfunction

All 4 comments

Use line('.') . '/' . line('$').

Would I have to add that manually somewhere? Is there no way to add it directly within the lightline config? As such:

'left': [ [ 'mode', ], [ 'fugitive', 'readonly', 'filename' ] ],
'right': [ [ 'syntastic', 'lineinfo', "line('.') . '/' . line('$')" ], [ 'filetype' ] ]

I'm fairly new to editing my vimrc files, so I'm a bit confused where I should be adding this. Any help would be much appreciated.

Please read the README.md or the help document. All the following examples should work for you. Choose the one you like.

let g:lightline = {
      \ 'component': {
      \   'lineinfo': "%{line('.') . '/' . line('$')}",
      \ },
      \ }
let g:lightline = {
      \ 'component': {
      \   'lineinfo': "%{printf('%03d/%03d', line('.'),  line('$'))}",
      \ },
      \ }
let g:lightline = {
      \ 'component_function': {
      \   'lineinfo': "MyLineinfo",
      \ },
      \ }
function! MyLineinfo() abort
  return line('.') . '/' . line('$')
endfunction
let g:lightline = {
      \ 'component_function': {
      \   'lineinfo': "MyLineinfo",
      \ },
      \ }
function! MyLineinfo()
  return printf('%03d/%03d', line('.'),  line('$'))
endfunction
let g:lightline = {
      \ 'active': {
      \   'right': [ [ 'syntastic', 'mylineinfo' ], [ 'filetype' ] ],
      \ },
      \ 'component_function': {
      \   'mylineinfo': "MyLineinfo",
      \ },
      \ }
function! MyLineinfo()
  return line('.') . '/' . line('$')
endfunction

I did, in fact, read the whole README. Sometimes its just difficult to not only know where to write what you want, but how to format it, correct syntax, etc. Especially if you're a beginner. Thank you for your help though, I really appreciate it.

Was this page helpful?
0 / 5 - 0 ratings