Skip to content

Instantly share code, notes, and snippets.

@c9s
Created June 19, 2010 02:57
Show Gist options
  • Save c9s/444528 to your computer and use it in GitHub Desktop.
Save c9s/444528 to your computer and use it in GitHub Desktop.
fun! EvalVimScriptRegion(s,e)
let lines = getline(a:s,a:e)
let file = tempname()
cal writefile(lines,file)
redir @e
silent exec ':source '.file
cal delete(file)
redraw
redir END
echo "Region evaluated."
if strlen(getreg('e')) > 0
10new
redraw
silent file "EvalResult"
setlocal noswapfile buftype=nofile bufhidden=wipe
setlocal nobuflisted nowrap cursorline nonumber fdc=0
" syntax init
set filetype="eval"
syn match ErrorLine +^E\d\+:.*$+
hi link ErrorLine Error
silent $put =@e
endif
endf
augroup VimEval
au!
au filetype vim :command! -range Eval :cal EvalVimScriptRegion(<line1>,<line2>)
au filetype vim :vnoremap <silent> e :Eval<CR>
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment