Create a gist now

Instantly share code, notes, and snippets.

@semanticart /sql.vim Secret
Created Jan 4, 2017

What would you like to do?
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