Wikia

Vim Tips Wiki

Watchlist Recent changes

Time your Vim commands

Redirected from VimTip1232

Tip 1232 Printable Monobook Previous Next

created 2006 · complexity intermediate · author muede · version 6.0


:command -complete=command -nargs=+ Time :let ct=strftime("%s") | exec <q-args> |let t=strftime("%s")| :echohl MoreMsg
 \|let min=(t - ct)/60 | let sec=(t - ct)%60
 \|let min = min < 10 ? "0".min : min | let sec= sec<10 ? "0".sec : sec | echo min.":".sec | echohl None

Possibly you need to change the strftime-string.

CommentsEdit

I usually was getting zero time used; that's probably what all the -1s are about. Here's an amended version using ten repeats. Obviously not all commands are suitable for use with ten repeats! So, feel free to modify maxrep to suit. As an example of use, consider

:Timer !ls

This is a version 7.0 script due to the printf().

com! -complete=command -nargs=+ Timer call s:Timer(<q-args>)
fun! s:Timer(cmd)
  " call Dfunc("Timer(cmd<".a:cmd.">)")
  let ct=strftime("%s")
  let maxrep= 10
  let repeat= 0
  while repeat < maxrep
    exec a:cmd
    let repeat= repeat + 1
  endwhile
  let t = strftime("%s")
  let dt = t - ct
  let min = (dt/maxrep)/60
  let sec = (dt/maxrep)%60
  let frac= (100*(dt%maxrep))/maxrep
  redraw!
  echohl MoreMsg
  echo printf("%d:%02d.%2d",min,sec,frac)
  echohl None
  " call Dret("Timer : t<".t.">")
endfun

Pages on Vim Tips Wiki

Add a Page
1,601pages on
this wiki

Latest Photos

Add a Photo
66photos on this wiki
See more >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki