-
-
Save semanticart/1a27c9da09e5e6eb3aa2d81c03a114f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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