Skip to content

Instantly share code, notes, and snippets.

@semanticart
Created January 4, 2017 22:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semanticart/1a27c9da09e5e6eb3aa2d81c03a114f5 to your computer and use it in GitHub Desktop.
Save semanticart/1a27c9da09e5e6eb3aa2d81c03a114f5 to your computer and use it in GitHub Desktop.
nnoremap <buffer> <localleader>r :call RunSQLFile()<cr>
function! RunSQLFile()
" Write the query file if it has changed
silent update
let l:cmd = g:sql_runner_cmd . ' -f ' . expand('%')
let l:results = systemlist(l:cmd)
" Give our result buffer a meaningful name
let l:name = '__SQL_Results__'
if bufwinnr(l:name) == -1
" Open a new split
execute 'vsplit ' . l:name
else
" Focus the existing window
execute bufwinnr(l:name) . 'wincmd w'
endif
" Clear out existing content
normal! gg"_dG
" Don't prompt to save the buffer
set buftype=nofile
" Insert our content
call append(0, l:results)
" Refocus the query window
execute 'wincmd p'
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment