Created
February 1, 2011 10:45
-
-
Save zbyhoo/805695 to your computer and use it in GitHub Desktop.
vim function to execute shell command and show output in vim 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 winnr < 0 ? 'botright new ' . fnameescape(command) : winnr . 'wincmd w' | |
setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap number | |
echo 'Execute ' . command . '...' | |
silent! execute 'silent %!'. command | |
silent! execute 'resize ' . line('$') | |
silent! redraw | |
silent! execute 'au BufUnload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w''' | |
silent! execute 'nnoremap <silent> <buffer> <LocalLeader>r :call <SID>ExecuteInShell(''' . command . ''')<CR>' | |
echo 'Shell command ' . command . ' executed.' | |
endfunction | |
command! -complete=shellcmd -nargs=+ Shell call s:ExecuteInShell(<q-args>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment