Show current file size in vim editor

9

I'm heavily using Vim to edit and work with my files, now I'm starting to open big files and it would be useful to see the file size directly from VIM itself.

Is there a way to show the current file size in vim ?

At the moment I'm doing :

:!ls -lah %

Is there an internal way to display the current file size ?

aleroot

Posted 2015-12-02T15:26:22.117

Reputation: 1 143

Answers

14

Hit g CTRL-g to see some statistics on the current file in the status line, including file size.

thakis

Posted 2015-12-02T15:26:22.117

Reputation: 241

this should be the accepted answer. it takes minimum keystroke to get the needed information – tdwong.star – 2018-12-03T20:05:09.097

11

Yes, there is an internal way to display current file size.

A simple way is as below:

:echo getfsize(expand(@%))

or little more verbose, as below:

:echo 'Size of ' @% ' file is ' getfsize(expand(@%)) ' bytes'

Alternatively, you can put it in a function and assign a key binding (map) for handy access. Something like this: Put following code in your vimrc file:

function! GetFilesize(file)
        let size        =        getfsize(expand(a:file))
        echo 'Size of ' a:file ' is ' size ' bytes'
endfunction

map <leader>s :call GetFilesize(@%)<CR>

And from within control mode, press \s (assuming <leader> is set to backslash).

Prasanna

Posted 2015-12-02T15:26:22.117

Reputation: 210