nvim: plugin/shell: Allows getting shell command output in temp buffer

Taken from
https://stackoverflow.com/questions/10493452/vim-open-a-temporary-buffer-displaying-executables-output
This commit is contained in:
Sanchayan Maity 2022-03-29 15:11:04 +05:30
parent 8d44f5ced6
commit d4a5bc933c

View file

@ -0,0 +1,13 @@
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>)