Skip to content

Instantly share code, notes, and snippets.

@dahu
Created June 13, 2015 00:43
Show Gist options
  • Save dahu/0009113ebac81bba6c10 to your computer and use it in GitHub Desktop.
Save dahu/0009113ebac81bba6c10 to your computer and use it in GitHub Desktop.
auto manage begin/end blocks in log file
" Barry Arthur, June 2015
" Auto manage Begin/End blocks in log file
" Manual function to create new block
function! SpasmLogAuto()
if ! exists('b:spasm')
let b:spasm = 1
$
let now = strftime('%c')
let last_entry = search('^\(Begin\)\|^\(End\)', 'bcpW')
if last_entry == 0 || last_entry == 3
call append('$', 'Begin ' . now)
else
call append('$', ['End','Begin ' . now])
end
$
endif
endfunction
function! SpasmLogManual()
silent! unlet b:spasm
call SpasmLogAuto()
endfunction
augroup SpasmLog
autocmd BufWinEnter *.log silent call SpasmLogAuto()
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment