Sanchayan Maity
d4a5bc933c
Taken from https://stackoverflow.com/questions/10493452/vim-open-a-temporary-buffer-displaying-executables-output
14 lines
663 B
VimL
14 lines
663 B
VimL
function! s:ExecuteInShell(command) " {{{
|
|
let command = join(map(split(a:command), 'expand(v:val)'))
|
|
let winnr = bufwinnr('^' . command . '$')
|
|
silent! execute winnr < 0 ? 'tabedit ' . fnameescape(command) : winnr . 'wincmd w'
|
|
setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap nonumber
|
|
silent! execute 'silent %!'. command
|
|
silent! redraw
|
|
silent! execute 'au BufUnload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w'''
|
|
silent! execute 'nnoremap <silent> <buffer> q :q<CR>'
|
|
echo 'Shell command ' . command . ' executed.'
|
|
endfunction " }}}
|
|
|
|
command! -complete=shellcmd -nargs=+ Shell call s:ExecuteInShell(<q-args>)
|