Skip to content

Instantly share code, notes, and snippets.

@thenoseman
Forked from c9s/.vimrc
Created September 13, 2012 20:05
Show Gist options
  • Save thenoseman/3717195 to your computer and use it in GitHub Desktop.
Save thenoseman/3717195 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