これは私の現在のものです。それは動作しますが、あなたが何か良いものを持っていれば、あなた自身の解決策を投稿してください!
また、Ctrl-V
とEnter
ボタンを挿入モードで押すと、^M
の行が形成されることに注意してください(スタックオーバーフローではそれをうまくコピーできません)。
" easily wrap the selected text in a time.time() statement for quick timing
fun! s:PythonTiming(line1, line2)
" mark line one && keep track of lines selected
execute 'normal!' 'me'
let l:numDiff = a:line2 - a:line1
" start timing
execute 'normal!' 'Ostart = time.time()'
" end timing
while line('.') < a:line2 + 1
execute 'normal!' 'j'
endwhile
execute 'normal!' 'oend = time.time()'
execute 'normal!' 'oprint; print("end - start: "); print(end - start)'
" add the `import time` statement if not already imported
let match = search('import time', 'nw')
if match == 0
silent! execute 'normal!' 'gg/import/^M'
execute 'normal!' 'oimport time'
endif
" go back to the initial mark
execute 'normal!' '`e'
endfun
command! -range Time :call s:PythonTiming(<line1>, <line2>)