5

When using netrw, (by :Vex or :Sex), the files can be displayed in different ways by pressing "i". And there is a view that the sizes of the files are displayed. However, the sizes are in bytes. Is there any way to show the sizes in a human readable way? like "ls -sh" in shell?

Thanks!

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
user3813057
  • 1,451
  • 3
  • 17
  • 26

2 Answers2

4

You could try netrw v155e with its size-styling parameter:

let g:netrw_sizestyle= "h"

Get it from http://www.drchip.org/astronaut/vim/index.html#NETRW

user21497
  • 811
  • 5
  • 5
3

For local file system listings, the netrw plugin uses Vim's getfsize() function. Its value would need to be converted to human units. Luckily, my ingo-library plugin provides such a function, so the following patch extends netrw (of the latest alpha version v154a from here) in such way:

--- netrw.vim.orig  2015-04-10 20:45:06.094760300 +0200
+++ netrw.vim   2015-04-10 20:47:38.387988100 +0200
@@ -9934,7 +9934,7 @@ fun! s:LocalListing()
"   call Decho("pfile   <".pfile.">")

    if w:netrw_liststyle == s:LONGLIST
-    let sz   = getfsize(filename)
+    let sz   = join(ingo#units#FormatBytesBinary(getfsize(filename)))
    let fsz  = strpart("               ",1,15-strlen(sz)).sz
    let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
"    call Decho("sz=".sz." fsz=".fsz)

If you also want relative file modification dates (e.g. 5 minutes ago) via a new option value g:netrw_timefmt = 'relative', you can apply the following patch instead:

--- netrw.vim.orig  2015-04-10 20:45:06.094760300 +0200
+++ netrw.vim   2015-04-10 20:55:40.937242900 +0200
@@ -9934,9 +9934,9 @@ fun! s:LocalListing()
"   call Decho("pfile   <".pfile.">")

    if w:netrw_liststyle == s:LONGLIST
-    let sz   = getfsize(filename)
+    let sz   = join(ingo#units#FormatBytesBinary(getfsize(filename)))
    let fsz  = strpart("               ",1,15-strlen(sz)).sz
-    let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
+    let pfile= pfile."\t".fsz."  ".(g:netrw_timefmt ==# 'relative' ? ingo#date#HumanReltime(localtime() - getftime(filename)) : strftime(g:netrw_timefmt,getftime(filename)))
"    call Decho("sz=".sz." fsz=".fsz)
    endif
Ingo Karkat
  • 17,819
  • 1
  • 45
  • 61
  • Hi, thanks for your reply. Do you know some lightweight solutions? Is there any way just to modify the .vimrc file since plug-in may be inconvenient for switching platform/machine. – user3813057 Apr 10 '15 at 21:10