Show current file size in vim editor
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 ?
Hit g CTRL-g
to see some statistics on the current file in the status line, including file size.
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).