Created
November 15, 2017 17:07
-
-
Save atomize/bca56a9a346a9f02b904622e04cf901d to your computer and use it in GitHub Desktop.
.vimrc function to run script in VIM and display output in split window
This file contains hidden or 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
function! s:ExecuteInShell(command) | |
let command = join(map(split(a:command), 'expand(v:val)')) | |
let winnr = bufwinnr('^' . command . '$') | |
silent! execute ':w' | |
silent! execute winnr < 0 ? 'vnew ' . fnameescape(command) : winnr . 'wincmd w' | |
setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap number | |
silent! execute 'silent %!'. command | |
silent! redraw | |
silent! execute 'au BufUnload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w''' | |
silent! execute 'nnoremap <silent> <buffer> <LocalLeader>r :call <SID>ExecuteInShell(''' . command . ''')<CR>' | |
silent! execute 'wincmd w' | |
" echo 'Shell command ' . command . ' executed.' | |
endfunction | |
command! -complete=shellcmd -nargs=+ Shell call s:ExecuteInShell(<q-args>) | |
cabbrev shell Shell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment